1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is Zip Writer Component.
16 * The Initial Developer of the Original Code is
17 * Dave Townsend <dtownsend@oxymoronical.com>.
19 * Portions created by the Initial Developer are Copyright (C) 2007
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK *****
39 #include
"nsISupports.idl"
41 interface nsIInputStream
;
42 interface nsIRequestObserver
;
44 interface nsIZipEntry
;
49 * An interface for a zip archiver that can be used from script.
51 * The interface supports both a synchronous method of archiving data and a
52 * queueing system to allow operations to be prepared then run in sequence
53 * with notification after completion.
55 * Operations added to the queue do not get performed until performQueue is
56 * called at which point they will be performed in the order that they were
59 * Operations performed on the queue will throw any errors out to the
62 * An attempt to perform a synchronous operation while the background queue
63 * is in progress will throw NS_ERROR_IN_PROGRESS.
65 * Entry names should use /'s as path separators and should not start with
68 * It is not generally necessary to add directory entries in order to add file
69 * entries within them, however it is possible that some zip programs may
70 * experience problems what that.
72 [scriptable
, uuid(6d4ef074
-206c
-4649-9884-57bc355864d6
)]
73 interface nsIZipWriter
: nsISupports
76 * Some predefined compression levels
78 const PRUint32 COMPRESSION_NONE
= 0;
79 const PRUint32 COMPRESSION_FASTEST
= 1;
80 const PRUint32 COMPRESSION_DEFAULT
= 6;
81 const PRUint32 COMPRESSION_BEST
= 9;
84 * Gets or sets the comment associated with the open zip file.
86 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened
88 attribute ACString comment
;
91 * Indicates that operations on the background queue are being performed.
93 readonly attribute
boolean inQueue
;
96 * The file that the zipwriter is writing to.
98 readonly attribute nsIFile file
;
103 * @param aFile the zip file to open
104 * @param aIoFlags the open flags for the zip file from prio.h
106 * @throws NS_ERROR_ALREADY_INITIALIZED if a zip file is already open
107 * @throws NS_ERROR_INVALID_ARG if aFile is null
108 * @throws NS_ERROR_FILE_NOT_FOUND if aFile does not exist and flags did
109 * not allow for creation
110 * @throws NS_ERROR_FILE_CORRUPTED if the file does not contain zip markers
111 * @throws <other-error> on failure to open zip file (most likely corrupt
112 * or unsupported form)
114 void open
(in nsIFile aFile
, in PRInt32 aIoFlags
);
117 * Returns a nsIZipEntry describing a specified zip entry or null if there
118 * is no such entry in the zip file
120 * @param aZipEntry the path of the entry
122 nsIZipEntry getEntry
(in AUTF8String aZipEntry
);
125 * Checks whether the zipfile contains an entry specified by zipEntry.
127 * @param aZipEntry the path of the entry
129 boolean hasEntry
(in AUTF8String aZipEntry
);
132 * Adds a new directory entry to the zip file. If aZipEntry does not end with
133 * "/" then it will be added.
135 * @param aZipEntry the path of the directory entry
136 * @param aModTime the modification time of the entry in microseconds
137 * @param aQueue adds the operation to the background queue. Will be
138 * performed when processQueue is called.
140 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened
141 * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the
143 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress
145 void addEntryDirectory
(in AUTF8String aZipEntry
, in PRTime aModTime
,
149 * Adds a new file or directory to the zip file. If the specified file is
150 * a directory then this will be equivalent to a call to
151 * addEntryDirectory(aZipEntry, aFile.lastModifiedTime, aQueue)
153 * @param aZipEntry the path of the file entry
154 * @param aCompression the compression level, 0 is no compression, 9 is best
155 * @param aFile the file to get the data and modification time from
156 * @param aQueue adds the operation to the background queue. Will be
157 * performed when processQueue is called.
159 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened
160 * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the zip
161 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress
162 * @throws NS_ERROR_FILE_NOT_FOUND if file does not exist
164 void addEntryFile
(in AUTF8String aZipEntry
,
165 in PRInt32 aCompression
, in nsIFile aFile
,
169 * Adds data from a channel to the zip file. If the operation is performed
170 * on the queue then the channel will be opened asynchronously, otherwise
171 * the channel must support being opened synchronously.
173 * @param aZipEntry the path of the file entry
174 * @param aModTime the modification time of the entry in microseconds
175 * @param aCompression the compression level, 0 is no compression, 9 is best
176 * @param aChannel the channel to get the data from
177 * @param aQueue adds the operation to the background queue. Will be
178 * performed when processQueue is called.
180 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened
181 * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the zip
182 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress
184 void addEntryChannel
(in AUTF8String aZipEntry
, in PRTime aModTime
,
185 in PRInt32 aCompression
, in nsIChannel aChannel
,
189 * Adds data from an input stream to the zip file.
191 * @param aZipEntry the path of the file entry
192 * @param aModTime the modification time of the entry in microseconds
193 * @param aCompression the compression level, 0 is no compression, 9 is best
194 * @param aStream the input stream to get the data from
195 * @param aQueue adds the operation to the background queue. Will be
196 * performed when processQueue is called.
198 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened
199 * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the zip
200 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress
202 void addEntryStream
(in AUTF8String aZipEntry
, in PRTime aModTime
,
203 in PRInt32 aCompression
, in nsIInputStream aStream
,
207 * Removes an existing entry from the zip file.
209 * @param aZipEntry the path of the entry to be removed
210 * @param aQueue adds the operation to the background queue. Will be
211 * performed when processQueue is called.
213 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened
214 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress
215 * @throws NS_ERROR_FILE_NOT_FOUND if no entry with the given path exists
216 * @throws <other-error> on failure to update the zip file
218 void removeEntry
(in AUTF8String aZipEntry
, in boolean aQueue
);
221 * Processes all queued items until complete or some error occurs. The
222 * observer will be notified when the first operation starts and when the
223 * last operation completes. Any failures will be passed to the observer.
224 * The zip writer will be busy until the queue is complete or some error
225 * halted processing of the queue early. In the event of an early failure,
226 * remaining items will stay in the queue and calling processQueue will
229 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened
230 * @throws NS_ERROR_IN_PROGRESS if the queue is already in progress
232 void processQueue
(in nsIRequestObserver aObserver
, in nsISupports aContext
);
235 * Closes the zip file.
237 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened
238 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress
239 * @throws <other-error> on failure to complete the zip file