1 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include
"nsISupports.idl"
13 [ptr] native PRFileDescStar
(PRFileDesc
);
15 interface nsIUTF8StringEnumerator
;
16 interface nsIInputStream
;
19 [scriptable
, builtinclass
, uuid(fad6f72f
-13d8
-4e26
-9173-53007a4afe71
)]
20 interface nsIZipEntry
: nsISupports
23 * The type of compression used for the item. The possible values and
24 * their meanings are defined in the zip file specification at
25 * http://www.pkware.com/business_and_developers/developer/appnote/
27 [infallible
] readonly attribute
unsigned short compression
;
29 * The compressed size of the data in the item.
31 [infallible
] readonly attribute
unsigned long size
;
33 * The uncompressed size of the data in the item.
35 [infallible
] readonly attribute
unsigned long realSize
;
37 * The CRC-32 hash of the file in the entry.
39 [infallible
] readonly attribute
unsigned long CRC32
;
41 * True if the name of the entry ends with '/' and false otherwise.
43 [infallible
] readonly attribute
boolean isDirectory
;
45 * The time at which this item was last modified.
47 readonly attribute PRTime lastModifiedTime
;
49 * Use this attribute to determine whether this item is an actual zip entry
50 * or is one synthesized for part of a real entry's path. A synthesized
51 * entry represents a directory within the zip file which has no
52 * corresponding entry within the zip file. For example, the entry for the
53 * directory foo/ in a zip containing exactly one entry for foo/bar.txt
54 * is synthetic. If the zip file contains an actual entry for a directory,
55 * this attribute will be false for the nsIZipEntry for that directory.
56 * It is impossible for a file to be synthetic.
58 [infallible
] readonly attribute
boolean isSynthetic
;
60 * The UNIX style file permissions of this item.
62 [infallible
] readonly attribute
unsigned long permissions
;
65 [scriptable
, uuid(9ba4ef54
-e0a0
-4f65
-9d23
-128482448885)]
66 interface nsIZipReader
: nsISupports
69 * Opens a zip file for reading.
70 * It is allowed to open with another file,
71 * but it needs to be closed first with close().
73 void open
(in nsIFile zipFile
);
76 * Opens a zip file inside a zip file for reading.
78 void openInner
(in nsIZipReader zipReader
, in AUTF8String zipEntry
);
81 * The file that represents the zip with which this zip reader was
82 * initialized. This will be null if there is no underlying file.
84 readonly attribute nsIFile file
;
87 * Closes a zip reader. Subsequent attempts to extract files or read from
88 * its input stream will result in an error.
90 * Subsequent attempts to access a nsIZipEntry obtained from this zip
91 * reader will cause unspecified behavior.
96 * Tests the integrity of the archive by performing a CRC check
97 * on each item expanded into memory. If an entry is specified
98 * the integrity of only that item is tested. If null (javascript)
99 * or ""_ns (c++) is passed in the integrity of all items
100 * in the archive are tested.
102 void test
(in AUTF8String aEntryName
);
105 * Extracts a zip entry into a local file specified by outFile.
106 * The entry must be stored in the zip in either uncompressed or
107 * DEFLATE-compressed format for the extraction to be successful.
108 * If the entry is a directory, the directory will be extracted
111 void extract
(in AUTF8String zipEntry
, in nsIFile outFile
);
114 * Returns a nsIZipEntry describing a specified zip entry.
116 nsIZipEntry getEntry
(in AUTF8String zipEntry
);
119 * Checks whether the zipfile contains an entry specified by entryName.
121 boolean hasEntry
(in AUTF8String zipEntry
);
124 * Returns a string enumerator containing the matching entry names.
127 * A regular expression used to find matching entries in the zip file.
128 * Set this parameter to null (javascript) or ""_ns (c++) or "*"
129 * to get all entries; otherwise, use the
132 * o * matches anything
133 * o ? matches one character
134 * o $ matches the end of the string
135 * o [abc] matches one occurrence of a, b, or c. The only character that
136 * must be escaped inside the brackets is ]. ^ and - must never
137 * appear in the first and second positions within the brackets,
138 * respectively. (In the former case, the behavior specified for
139 * '[^az]' will happen.)
140 * o [a-z] matches any character between a and z. The characters a and z
141 * must either both be letters or both be numbers, with the
142 * character represented by 'a' having a lower ASCII value than
143 * the character represented by 'z'.
144 * o [^az] matches any character except a or z. If ] is to appear inside
145 * the brackets as a character to not match, it must be escaped.
146 * o pat~pat2 returns matches to the pattern 'pat' which do not also match
147 * the pattern 'pat2'. This may be used to perform filtering
148 * upon the results of one pattern to remove all matches which
149 * also match another pattern. For example, because '*'
150 * matches any string and '*z*' matches any string containing a
151 * 'z', '*~*z*' will match all strings except those containing
152 * a 'z'. Note that a pattern may not use '~' multiple times,
153 * so a string such as '*~*z*~*y*' is not a valid pattern.
154 * o (foo|bar) will match either the pattern foo or the pattern bar.
155 * Neither of the patterns foo or bar may use the 'pat~pat2'
156 * syntax described immediately above.
157 * o \ will escape a special character. Escaping is required for all
158 * special characters unless otherwise specified.
159 * o All other characters match case-sensitively.
161 * An aPattern not conforming to this syntax has undefined behavior.
163 * @throws NS_ERROR_ILLEGAL_VALUE on many but not all invalid aPattern
166 nsIUTF8StringEnumerator findEntries
(in AUTF8String aPattern
);
169 * Returns an input stream containing the contents of the specified zip
171 * @param zipEntry the name of the entry to open the stream from
173 nsIInputStream getInputStream
(in AUTF8String zipEntry
);
176 * Returns an input stream containing the contents of the specified zip
177 * entry. If the entry refers to a directory (ends with '/'), a directory stream
178 * is opened, otherwise the contents of the file entry is returned.
179 * @param aJarSpec the Spec of the URI for the JAR (only used for directory streams)
180 * @param zipEntry the name of the entry to open the stream from
182 nsIInputStream getInputStreamWithSpec
(in AUTF8String aJarSpec
, in AUTF8String zipEntry
);
185 ////////////////////////////////////////////////////////////////////////////////
188 [scriptable
, uuid(31179807-9fcd
-46c4
-befa
-2ade209a394b
)]
189 interface nsIZipReaderCache
: nsISupports
192 * Initializes a new zip reader cache.
193 * @param cacheSize - the number of released entries to maintain before
194 * beginning to throw some out (note that the number of outstanding
195 * entries can be much greater than this number -- this is the count
196 * for those otherwise unused entries)
198 void init
(in unsigned long cacheSize
);
201 * Returns a (possibly shared) nsIZipReader for an nsIFile.
203 * If the zip reader for given file is not in the cache, a new zip reader
204 * is created, initialized, and opened (see nsIZipReader::init and
205 * nsIZipReader::open). Otherwise the previously created zip reader is
208 * @note If someone called close() on the shared nsIZipReader, this method
209 * will return the closed zip reader.
211 nsIZipReader getZip
(in nsIFile zipFile
);
214 * Like getZip(), returns a (possibly shared) nsIZipReader for an nsIFile,
215 * but if a zip reader for the given file is not in the cache, returns
216 * error NS_ERROR_CACHE_KEY_NOT_FOUND rather than creating a new reader.
218 * @note If someone called close() on the shared nsIZipReader, this method
219 * will return the closed zip reader.
221 nsIZipReader getZipIfCached
(in nsIFile zipFile
);
224 * returns true if this zipreader already has this file cached
226 bool isCached
(in nsIFile zipFile
);
229 * Returns a (possibly shared) nsIZipReader for a zip inside another zip
233 nsIZipReader getInnerZip
(in nsIFile zipFile
, in AUTF8String zipEntry
);
236 * Returns the cached NSPR file descriptor of the file.
237 * Note: currently not supported on Windows platform.
239 PRFileDescStar getFd
(in nsIFile zipFile
);
242 ////////////////////////////////////////////////////////////////////////////////
246 #define NS_ZIPREADER_CID \
247 { /* 88e2fd0b-f7f4-480c-9483-7846b00e8dad */ \
248 0x88e2fd0b, 0xf7f4, 0x480c, \
249 { 0x94, 0x83, 0x78, 0x46, 0xb0, 0x0e, 0x8d, 0xad } \
252 #define NS_ZIPREADERCACHE_CID \
253 { /* 608b7f6f-4b60-40d6-87ed-d933bf53d8c1 */ \
254 0x608b7f6f, 0x4b60, 0x40d6, \
255 { 0x87, 0xed, 0xd9, 0x33, 0xbf, 0x53, 0xd8, 0xc1 } \
260 ////////////////////////////////////////////////////////////////////////////////