michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: #include "nsISupports.idl" michael@0: interface nsIChannel; michael@0: interface nsIInputStream; michael@0: interface nsIRequestObserver; michael@0: interface nsIFile; michael@0: interface nsIZipEntry; michael@0: michael@0: /** michael@0: * nsIZipWriter michael@0: * michael@0: * An interface for a zip archiver that can be used from script. michael@0: * michael@0: * The interface supports both a synchronous method of archiving data and a michael@0: * queueing system to allow operations to be prepared then run in sequence michael@0: * with notification after completion. michael@0: * michael@0: * Operations added to the queue do not get performed until performQueue is michael@0: * called at which point they will be performed in the order that they were michael@0: * added to the queue. michael@0: * michael@0: * Operations performed on the queue will throw any errors out to the michael@0: * observer. michael@0: * michael@0: * An attempt to perform a synchronous operation while the background queue michael@0: * is in progress will throw NS_ERROR_IN_PROGRESS. michael@0: * michael@0: * Entry names should use /'s as path separators and should not start with michael@0: * a /. michael@0: * michael@0: * It is not generally necessary to add directory entries in order to add file michael@0: * entries within them, however it is possible that some zip programs may michael@0: * experience problems what that. michael@0: */ michael@0: [scriptable, uuid(3ca10750-797e-4a22-bcfe-66170b5e96dd)] michael@0: interface nsIZipWriter : nsISupports michael@0: { michael@0: /** michael@0: * Some predefined compression levels michael@0: */ michael@0: const uint32_t COMPRESSION_NONE = 0; michael@0: const uint32_t COMPRESSION_FASTEST = 1; michael@0: const uint32_t COMPRESSION_DEFAULT = 6; michael@0: const uint32_t COMPRESSION_BEST = 9; michael@0: michael@0: /** michael@0: * Gets or sets the comment associated with the open zip file. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened michael@0: */ michael@0: attribute ACString comment; michael@0: michael@0: /** michael@0: * Indicates that operations on the background queue are being performed. michael@0: */ michael@0: readonly attribute boolean inQueue; michael@0: michael@0: /** michael@0: * The file that the zipwriter is writing to. michael@0: */ michael@0: readonly attribute nsIFile file; michael@0: michael@0: /** michael@0: * Opens a zip file. michael@0: * michael@0: * @param aFile the zip file to open michael@0: * @param aIoFlags the open flags for the zip file from prio.h michael@0: * michael@0: * @throws NS_ERROR_ALREADY_INITIALIZED if a zip file is already open michael@0: * @throws NS_ERROR_INVALID_ARG if aFile is null michael@0: * @throws NS_ERROR_FILE_NOT_FOUND if aFile does not exist and flags did michael@0: * not allow for creation michael@0: * @throws NS_ERROR_FILE_CORRUPTED if the file does not contain zip markers michael@0: * @throws on failure to open zip file (most likely corrupt michael@0: * or unsupported form) michael@0: */ michael@0: void open(in nsIFile aFile, in int32_t aIoFlags); michael@0: michael@0: /** michael@0: * Returns a nsIZipEntry describing a specified zip entry or null if there michael@0: * is no such entry in the zip file michael@0: * michael@0: * @param aZipEntry the path of the entry michael@0: */ michael@0: nsIZipEntry getEntry(in AUTF8String aZipEntry); michael@0: michael@0: /** michael@0: * Checks whether the zipfile contains an entry specified by zipEntry. michael@0: * michael@0: * @param aZipEntry the path of the entry michael@0: */ michael@0: boolean hasEntry(in AUTF8String aZipEntry); michael@0: michael@0: /** michael@0: * Adds a new directory entry to the zip file. If aZipEntry does not end with michael@0: * "/" then it will be added. michael@0: * michael@0: * @param aZipEntry the path of the directory entry michael@0: * @param aModTime the modification time of the entry in microseconds michael@0: * @param aQueue adds the operation to the background queue. Will be michael@0: * performed when processQueue is called. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened michael@0: * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the michael@0: * file michael@0: * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress michael@0: */ michael@0: void addEntryDirectory(in AUTF8String aZipEntry, in PRTime aModTime, michael@0: in boolean aQueue); michael@0: michael@0: /** michael@0: * Adds a new file or directory to the zip file. If the specified file is michael@0: * a directory then this will be equivalent to a call to michael@0: * addEntryDirectory(aZipEntry, aFile.lastModifiedTime, aQueue) michael@0: * michael@0: * @param aZipEntry the path of the file entry michael@0: * @param aCompression the compression level, 0 is no compression, 9 is best michael@0: * @param aFile the file to get the data and modification time from michael@0: * @param aQueue adds the operation to the background queue. Will be michael@0: * performed when processQueue is called. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened michael@0: * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the zip michael@0: * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress michael@0: * @throws NS_ERROR_FILE_NOT_FOUND if file does not exist michael@0: */ michael@0: void addEntryFile(in AUTF8String aZipEntry, michael@0: in int32_t aCompression, in nsIFile aFile, michael@0: in boolean aQueue); michael@0: michael@0: /** michael@0: * Adds data from a channel to the zip file. If the operation is performed michael@0: * on the queue then the channel will be opened asynchronously, otherwise michael@0: * the channel must support being opened synchronously. michael@0: * michael@0: * @param aZipEntry the path of the file entry michael@0: * @param aModTime the modification time of the entry in microseconds michael@0: * @param aCompression the compression level, 0 is no compression, 9 is best michael@0: * @param aChannel the channel to get the data from michael@0: * @param aQueue adds the operation to the background queue. Will be michael@0: * performed when processQueue is called. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened michael@0: * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the zip michael@0: * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress michael@0: */ michael@0: void addEntryChannel(in AUTF8String aZipEntry, in PRTime aModTime, michael@0: in int32_t aCompression, in nsIChannel aChannel, michael@0: in boolean aQueue); michael@0: michael@0: /** michael@0: * Adds data from an input stream to the zip file. michael@0: * michael@0: * @param aZipEntry the path of the file entry michael@0: * @param aModTime the modification time of the entry in microseconds michael@0: * @param aCompression the compression level, 0 is no compression, 9 is best michael@0: * @param aStream the input stream to get the data from michael@0: * @param aQueue adds the operation to the background queue. Will be michael@0: * performed when processQueue is called. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened michael@0: * @throws NS_ERROR_FILE_ALREADY_EXISTS if the path already exists in the zip michael@0: * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress michael@0: */ michael@0: void addEntryStream(in AUTF8String aZipEntry, in PRTime aModTime, michael@0: in int32_t aCompression, in nsIInputStream aStream, michael@0: in boolean aQueue); michael@0: michael@0: /** michael@0: * Removes an existing entry from the zip file. michael@0: * michael@0: * @param aZipEntry the path of the entry to be removed michael@0: * @param aQueue adds the operation to the background queue. Will be michael@0: * performed when processQueue is called. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened michael@0: * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress michael@0: * @throws NS_ERROR_FILE_NOT_FOUND if no entry with the given path exists michael@0: * @throws on failure to update the zip file michael@0: */ michael@0: void removeEntry(in AUTF8String aZipEntry, in boolean aQueue); michael@0: michael@0: /** michael@0: * Processes all queued items until complete or some error occurs. The michael@0: * observer will be notified when the first operation starts and when the michael@0: * last operation completes. Any failures will be passed to the observer. michael@0: * The zip writer will be busy until the queue is complete or some error michael@0: * halted processing of the queue early. In the event of an early failure, michael@0: * remaining items will stay in the queue and calling processQueue will michael@0: * continue. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened michael@0: * @throws NS_ERROR_IN_PROGRESS if the queue is already in progress michael@0: */ michael@0: void processQueue(in nsIRequestObserver aObserver, in nsISupports aContext); michael@0: michael@0: /** michael@0: * Closes the zip file. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if no zip file has been opened michael@0: * @throws NS_ERROR_IN_PROGRESS if another operation is currently in progress michael@0: * @throws on failure to complete the zip file michael@0: */ michael@0: void close(); michael@0: michael@0: /** michael@0: * Make all stored(uncompressed) files align to given alignment size. michael@0: * michael@0: * @param aAlignSize is the alignment size, valid values from 2 to 32768, and michael@0: must be power of 2. michael@0: * michael@0: * @throws NS_ERROR_INVALID_ARG if aAlignSize is invalid michael@0: * @throws on failure to update the zip file michael@0: */ michael@0: void alignStoredFiles(in uint16_t aAlignSize); michael@0: };