nsIZipWriter.idl (8822B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 */ 5 6 #include "nsISupports.idl" 7 interface nsIChannel; 8 interface nsIInputStream; 9 interface nsIRequestObserver; 10 interface nsIFile; 11 interface nsIZipEntry; 12 13 /** 14 * nsIZipWriter 15 * 16 * An interface for a zip archiver that can be used from script. 17 * 18 * The interface supports both a synchronous method of archiving data and a 19 * queueing system to allow operations to be prepared then run in sequence 20 * with notification after completion. 21 * 22 * Operations added to the queue do not get performed until performQueue is 23 * called at which point they will be performed in the order that they were 24 * added to the queue. 25 * 26 * Operations performed on the queue will throw any errors out to the 27 * observer. 28 * 29 * An attempt to perform a synchronous operation while the background queue 30 * is in progress will throw NS_ERROR_IN_PROGRESS. 31 * 32 * Entry names should use /'s as path separators and should not start with 33 * a /. 34 * 35 * It is not generally necessary to add directory entries in order to add file 36 * entries within them, however it is possible that some zip programs may 37 * experience problems what that. 38 */ 39 [scriptable, uuid(3ca10750-797e-4a22-bcfe-66170b5e96dd)] 40 interface nsIZipWriter : nsISupports 41 { 42 /** 43 * Some predefined compression levels 44 */ 45 const uint32_t COMPRESSION_NONE = 0; 46 const uint32_t COMPRESSION_FASTEST = 1; 47 const uint32_t COMPRESSION_DEFAULT = 6; 48 const uint32_t COMPRESSION_BEST = 9; 49 50 /** 51 * Gets or sets the comment associated with the open zip file. 52 * 53 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened 54 */ 55 attribute ACString comment; 56 57 /** 58 * Indicates that operations on the background queue are being performed. 59 */ 60 readonly attribute boolean inQueue; 61 62 /** 63 * The file that the zipwriter is writing to. 64 */ 65 readonly attribute nsIFile file; 66 67 /** 68 * Opens a zip file. 69 * 70 * @param aFile the zip file to open 71 * @param aIoFlags the open flags for the zip file from prio.h 72 * 73 * @throws NS_ERROR_ALREADY_INITIALIZED if a zip file is already open 74 * @throws NS_ERROR_INVALID_ARG if aFile is null 75 * @throws NS_ERROR_FILE_NOT_FOUND if aFile does not exist and flags did 76 * not allow for creation 77 * @throws NS_ERROR_FILE_CORRUPTED if the file does not contain zip markers 78 * @throws <other-error> on failure to open zip file (most likely corrupt 79 * or unsupported form) 80 */ 81 void open(in nsIFile aFile, in int32_t aIoFlags); 82 83 /** 84 * Returns a nsIZipEntry describing a specified zip entry or null if there 85 * is no such entry in the zip file 86 * 87 * @param aZipEntry the path of the entry 88 */ 89 nsIZipEntry getEntry(in AUTF8String aZipEntry); 90 91 /** 92 * Checks whether the zipfile contains an entry specified by zipEntry. 93 * 94 * @param aZipEntry the path of the entry 95 */ 96 boolean hasEntry(in AUTF8String aZipEntry); 97 98 /** 99 * Adds a new directory entry to the zip file. If aZipEntry does not end with 100 * "/" then it will be added. 101 * 102 * @param aZipEntry the path of the directory entry 103 * @param aModTime the modification time of the entry in microseconds 104 * @param aQueue adds the operation to the background queue. Will be 105 * performed when processQueue is called. 106 * 107 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened 108 * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the 109 * file 110 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress 111 * @throws NS_ERROR_INVALID_ARG if aModTime is older than 1980-1-1 112 */ 113 void addEntryDirectory(in AUTF8String aZipEntry, in PRTime aModTime, 114 in boolean aQueue); 115 116 /** 117 * Adds a new file or directory to the zip file. If the specified file is 118 * a directory then this will be equivalent to a call to 119 * addEntryDirectory(aZipEntry, aFile.lastModifiedTime, aQueue) 120 * 121 * @param aZipEntry the path of the file entry 122 * @param aCompression the compression level, 0 is no compression, 9 is best 123 * @param aFile the file to get the data and modification time from 124 * @param aQueue adds the operation to the background queue. Will be 125 * performed when processQueue is called. 126 * 127 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened 128 * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the zip 129 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress 130 * @throws NS_ERROR_FILE_NOT_FOUND if file does not exist 131 */ 132 void addEntryFile(in AUTF8String aZipEntry, 133 in int32_t aCompression, in nsIFile aFile, 134 in boolean aQueue); 135 136 /** 137 * Adds data from a channel to the zip file. If the operation is performed 138 * on the queue then the channel will be opened asynchronously, otherwise 139 * the channel must support being opened synchronously. 140 * 141 * @param aZipEntry the path of the file entry 142 * @param aModTime the modification time of the entry in microseconds 143 * @param aCompression the compression level, 0 is no compression, 9 is best 144 * @param aChannel the channel to get the data from 145 * @param aQueue adds the operation to the background queue. Will be 146 * performed when processQueue is called. 147 * 148 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened 149 * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the zip 150 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress 151 * @throws NS_ERROR_INVALID_ARG if aModTime is older than 1980-1-1 152 */ 153 void addEntryChannel(in AUTF8String aZipEntry, in PRTime aModTime, 154 in int32_t aCompression, in nsIChannel aChannel, 155 in boolean aQueue); 156 157 /** 158 * Adds data from an input stream to the zip file. 159 * 160 * @param aZipEntry the path of the file entry 161 * @param aModTime the modification time of the entry in microseconds 162 * @param aCompression the compression level, 0 is no compression, 9 is best 163 * @param aStream the input stream to get the data from 164 * @param aQueue adds the operation to the background queue. Will be 165 * performed when processQueue is called. 166 * 167 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened 168 * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the zip 169 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress 170 * @throws NS_ERROR_INVALID_ARG if aModTime is older than 1980-1-1 171 */ 172 void addEntryStream(in AUTF8String aZipEntry, in PRTime aModTime, 173 in int32_t aCompression, in nsIInputStream aStream, 174 in boolean aQueue); 175 176 /** 177 * Removes an existing entry from the zip file. 178 * 179 * @param aZipEntry the path of the entry to be removed 180 * @param aQueue adds the operation to the background queue. Will be 181 * performed when processQueue is called. 182 * 183 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened 184 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress 185 * @throws NS_ERROR_FILE_NOT_FOUND if no entry with the given path exists 186 * @throws <other-error> on failure to update the zip file 187 */ 188 void removeEntry(in AUTF8String aZipEntry, in boolean aQueue); 189 190 /** 191 * Processes all queued items until complete or some error occurs. The 192 * observer will be notified when the first operation starts and when the 193 * last operation completes. Any failures will be passed to the observer. 194 * The zip writer will be busy until the queue is complete or some error 195 * halted processing of the queue early. In the event of an early failure, 196 * remaining items will stay in the queue and calling processQueue will 197 * continue. 198 * 199 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened 200 * @throws NS_ERROR_IN_PROGRESS if the queue is already in progress 201 */ 202 void processQueue(in nsIRequestObserver aObserver, in nsISupports aContext); 203 204 /** 205 * Closes the zip file. 206 * 207 * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened 208 * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress 209 * @throws <other-error> on failure to complete the zip file 210 */ 211 void close(); 212 213 /** 214 * Make all stored(uncompressed) files align to given alignment size. 215 * 216 * @param aAlignSize is the alignment size, valid values from 2 to 32768, and 217 must be power of 2. 218 * 219 * @throws NS_ERROR_INVALID_ARG if aAlignSize is invalid 220 * @throws <other-error> on failure to update the zip file 221 */ 222 void alignStoredFiles(in uint16_t aAlignSize); 223 };