Visit Mozilla.org

nsIZipReader

From MDC

Contents

nsIZipReader is defined in modules/libjar/nsIZipReader.idl. It is scriptable and unfrozen (hasn't changed since Mozilla 1.9).

Inherits from: nsISupports

Implemented by: @mozilla.org/libjar/zip-reader;1. To create an instance, use:

var zReader = Components.classes["@mozilla.org/libjar/zip-reader;1"]
                        .createInstance(Components.interfaces.nsIZipReader);

[edit] Method overview

void open(in nsIFile zipFile)
void close()
void test(in string aEntryName)
void extract(in string zipEntry, in nsIFile outFile)
nsIZipEntry getEntry(in string zipEntry)
boolean hasEntry(in AUTF8String zipEntry)
nsIUTF8StringEnumerator findEntries(in string aPattern)
nsIInputStream getInputStream(in string zipEntry)
nsIInputStream getInputStreamWithSpec(in AUTF8String aJarSpec, in string zipEntry)

[edit] Attributes

Attribute Type Description
file readonly attribute nsIFile The file that represents the zip with which this zip reader was initialized.

[edit] Methods

[edit] open()

Opens a zip file for reading. It is allowed to open with another file, but it needs to be closed first with close().

void open(in nsIFile zipFile)
[edit] Parameters
zipFile
The zip file to open.

[edit] close()

Closes a zip reader. Subsequent attempts to extract files or read from its input stream will result in an error.

void close()

[edit] test()

Tests the integrity of the archive by performing a CRC check on each item expanded into memory. If an entry is specified the integrity of only that item is tested. If NULL is passed in the integrity of all items in the archive are tested.

void test(in string aEntryName)
[edit] Parameters
aEntryName
The single entity to check or NULL for checking all entries in the archive.

[edit] extract()

Extracts a zip entry into a local file specified by outFile. The entry must be stored in the zip in either uncompressed or DEFLATE-compressed format for the extraction to be successful. If the entry is a directory, the directory will be extracted non-recursively.

void extract(in string zipEntry, in nsIFile outFile)
[edit] Parameters
zipEntry
The zip entry to extract
outFile
The local file destination used to extract the zip entry

[edit] getEntry()

Returns a nsIZipEntry describing a specified zip entry.

nsIZipEntry getEntry(in string zipEntry)
[edit] Parameters
zipEntry
The zip entry
[edit] Return value

The nsIZipEntry for the given zip entry.

[edit] hasEntry()

Checks whether the zipfile contains an entry specified by entryName.

boolean hasEntry(in AUTF8String zipEntry)
[edit] Parameters
[edit] Return value

boolean value, true if the zip entry exists, false is it does not exist.

[edit] findEntries()

Returns a string enumerator containing the matching entry names.

nsIUTF8StringEnumerator findEntries(in string aPattern)
[edit] Parameters
aPattern
A regular expression used to find matching entries in the zip file. Set this parameter to null to get all entries; otherwise, use the following syntax:
[edit] Exceptions thrown
NS_ERROR_ILLEGAL_VALUE
on many but not all invalid aPattern values.
[edit] Return value

the nsIUTF8StringEnumerator containing the matching entry names.

[edit] getInputStream()

Returns an input stream containing the contents of the specified zip entry.

nsIInputStream getInputStream(in string zipEntry)
[edit] Parameters
zipEntry
the name of the entry to open the stream from
[edit] Return value

the nsIInputStream containing the contents of the specified zip entry.

[edit] getInputStreamWithSpec()

Returns an input stream containing the contents of the specified zip entry. If the entry refers to a directory (ends with '/'), a directory stream is opened, otherwise the contents of the file entry is returned.

nsIInputStream getInputStreamWithSpec(in AUTF8String aJarSpec, in string zipEntry)
[edit] Parameters
aJarSpec
the Spec of the URI for the JAR (only used for directory streams)
[edit] Return value

the nsIInputStream containing the contents of the specified zip entry.

[edit] See also

nsIZipEntry