Fork me on GitHub

zip.js

Filesystem API

zip-fs.js is an optional script that helps to manipulate a zip file easily. It provides a virtual filesystem API implementation for zip files.

Contents

  1. Zip filesystem
  2. Zip entry
  3. Zip file entry
  4. Zip directory entry

  1. Zip filesystem

    zip.fs.FS()

    Zip filesystem constructor
    A zip.fs.FS object stores an entire filesystem. The root property stores a ZipDirectoryEntry object representing the root directory of the zip.

    Attributes

    root (ZipDirectoryEntry)
    the ZipDirectoryEntry object referencing the root directory of the filesystem

    Methods

    FS.prototype.importBlob(blob, onend[, onerror])

    Reset the filesystem and import a zipped content stored in a Blob object.

    Parameters:

    blob (Blob)
    the Blob object
    onend (Function)
    success callback function
    onerror (Function)
    error callback function

    FS.prototype.importData64URI(dataURI, onend[, onerror])

    Reset the filesystem and import a zipped content stored in a data URI string.

    Parameters:

    dataURI (string)
    The data URI
    onend (Function)
    success callback function
    onerror (Function)
    error callback function

    FS.prototype.importHttpContent(URL, useRangeHeader, onend[, onerror])

    Reset the filesystem and import a zipped content retrieved from a URL.

    Parameters:

    URL (string)
    the URL
    useRangeHeader (boolean)
    if true then HTTP "Range" header will be used to get zip data
    onend (Function)
    success callback function
    onerror (Function)
    error callback function

    FS.prototype.exportBlob(onend[, onprogress, onerror])

    Export zipped content from the filesystem in a Blob object.

    Parameters:

    onend (Function)
    success callback function returning the zipped content as parameter
    onprogress (Function)
    progress callback function returning an index (number) and a max value (number) as parameters
    onerror (Function)
    error callback function

    FS.prototype.exportData64URI(onend[, onprogress, onerror])

    Export zipped content from the filesystem in a data URI.

    Parameters:

    onend (Function)
    success callback function returning the zipped content as parameter
    onprogress (Function)
    progress callback function returning an index (number) and a max value (number) as parameters
    onerror (Function)
    error callback function

    FS.prototype.exportFileEntry(fileEntry, onend[, onprogress, onerror])

    Export zipped content from the filesystem in a FileEntry object.

    Parameters:

    fileEntry (FileEntry)
    the FileEntry object
    onend (Function)
    success callback function returning the zipped content as parameter
    onprogress (Function)
    progress callback function returning an index (number) and a max value (number) as parameters
    onerror (Function)
    error callback function

    FS.prototype.getById(entryId)

    Get a ZipEntry object given a unique entry id.

    Parameters:

    entryId (number)
    the entry id

    FS.prototype.find(fullname)

    Get a ZipEntry object given a unique entry full filename.

    Parameters:

    fullname (string)
    the entry full filename

    FS.prototype.remove(zipEntry)

    Remove a ZipEntry object from the virtual filesystem.

    Parameters:

    zipEntry (ZipEntry)
    the entry to remove

  2. Zip entry

    ZipEntry()

    ZipEntry constructor
    Each ZipEntry object represents a node in the zip directory tree. A file in the zip is a ZipFileEntry with a ZipEntry object as prototype. A directory in the zip is a ZipDirectoryEntry with a ZipEntry object as prototype.

    Attributes

    name (string)
    the entry filename
    directory (boolean)
    true if the entry is a ZipDirectoryEntry object
    children (Array of ZipEntry)
    the entry children, empty if the entry is a ZipFileEntry object
    id (number)
    the entry unique id

    Methods

    ZipEntry.prototype.getFileEntry(fileEntry, onend[, onprogress, onerror])

    Store entry content into a FileEntry object.

    Parameters:

    fileEntry (FileEntry)
    the FileEntry object
    onend (Function)
    success callback function
    onprogress (Function)
    progress callback function returning an index (number) and a max value (number) as parameters
    onerror (Function)
    error callback function

    ZipEntry.prototype.moveTo(directory)

    Move this entry into the ZipDirectoryEntry target object.

    Parameters:

    directory (ZipDirectoryEntry)
    the ZipDirectoryEntry target object

    ZipEntry.prototype.getFullname()

    Get this entry full name.

    Return

    string
    the entry full name

    ZipEntry.prototype.isDescendantOf(ancestor)

    Test if this entry is a descendant of ancestor directory entry.

    Parameters:

    ancestor (ZipDirectoryEntry)
    the ancestor

    Return

    boolean
    true if this entry is a descendant of ancestor directory entry
  3. Zip file entry

    ZipFileEntry()

    ZipFileEntry constructor

    Methods

    ZipFileEntry.prototype.getText(callback[, checkCrc32])

    Get file entry content as a string.

    Parameters:

    callback (Function)
    success callback function returning the unzipped content as parameter
    checkCrc32 (boolean)
    pass true to verify data integrity

    ZipFileEntry.prototype.getBlob(mimeType, callback[, checkCrc32])

    Get file entry content as a Blob object.

    Parameters:

    mimeType (string)
    data MIME type
    callback (Function)
    success callback function returning the unzipped content as parameter
    checkCrc32 (boolean)
    pass true to verify data integrity

    ZipFileEntry.prototype.getData64URI(mimeType, callback[, checkCrc32])

    Get file entry content as a data URI string.

    Parameters:

    mimeType (string)
    data MIME type
    callback (Function)
    success callback function returning the unzipped content as parameter
    checkCrc32 (boolean)
    pass true to verify data integrity
  4. Zip directory entry

    ZipDirectoryEntry()

    ZipDirectoryEntry constructor

    Methods

    ZipDirectoryEntry.prototype.addDirectory(name)

    Add a directory into this directory entry.

    Parameters:

    name (string)
    the directory name

    Return

    ZipDirectoryEntry
    the new ZipDirectoryEntry object

    ZipDirectoryEntry.prototype.addBlob(name, blob)

    Add a Blob object file into this directory entry.

    Parameters:

    name (string)
    the file name
    blob (Blob)
    the Blob content

    Return

    ZipFileEntry
    the new ZipFileEntry object

    ZipDirectoryEntry.prototype.addText(name, text)

    Add a text file into this directory entry.

    Parameters:

    name (string)
    the file name
    text (string)
    the text content

    Return

    ZipFileEntry
    the new ZipFileEntry object

    ZipDirectoryEntry.prototype.addData64URI(name, dataURI)

    Add a data URI file into this directory entry.

    Parameters:

    name (string)
    the file name
    text (string)
    the data URI content

    Return

    ZipFileEntry
    the new ZipFileEntry object

    ZipDirectoryEntry.prototype.addHttpContent(name, URL, size, useRangeHeader)

    Add a content retrieved from a URL into this directory entry.

    Parameters:

    name (string)
    the file name
    URL (string)
    the content URL
    size (number)
    the content size
    useRangeHeader (boolean)
    if true then HTTP "Range" header will be used to get content

    Return

    ZipFileEntry
    the new ZipFileEntry object

    ZipDirectoryEntry.prototype.addFileEntry(entry, callback[, onerror])

    Add a FileEntry or a DirectoryEntry into this directory entry. If entry is a FileEntry object then FileEntry.prototype.file() function is called in order to get its content. If entry is a DirectoryEntry object then all its children (file or directory) will be added recursively into this directory entry.

    Parameters:

    entry (FileEntry or DirectoryEntry)
    the FileEntry or DirectoryEntry object
    callback (Function)
    success callback function
    onerror (Function)
    error callback function

    ZipDirectoryEntry.prototype.importBlob(blob, onend[, onerror])

    Import a zipped content stored in a Blob object into this directory entry

    Parameters:

    blob (Blob)
    the Blob object
    onend (Function)
    success callback function
    onerror (Function)
    error callback function

    ZipDirectoryEntry.prototype.importData64URI(dataURI, onend[, onerror])

    Import a zipped content stored in a data URI string into this directory entry.

    Parameters:

    dataURI (string)
    The data URI
    onend (Function)
    success callback function
    onerror (Function)
    error callback function

    ZipDirectoryEntry.prototype.importHttpContent(URL, useRangeHeader, onend[, onerror])

    Import a zipped content retrieved from a URL into this directory entry.

    Parameters:

    URL (string)
    the URL
    useRangeHeader (boolean)
    if true then HTTP "Range" header will be used to get zip data
    onend (Function)
    success callback function
    onerror (Function)
    error callback function

    ZipDirectoryEntry.prototype.exportBlob(onend[, onprogress, onerror])

    Export zipped content in a Blob object from this directory entry.

    Parameters:

    onend (Function)
    success callback function returning the zipped content as parameter
    onprogress (Function)
    progress callback function returning an index (number) and a max value (number) as parameters
    onerror (Function)
    error callback function

    ZipDirectoryEntry.prototype.exportData64URI(onend[, onprogress, onerror])

    Export zipped content in a data URI from this directory entry.

    Parameters:

    onend (Function)
    success callback function returning the zipped content as parameter
    onprogress (Function)
    progress callback function returning an index (number) and a max value (number) as parameters
    onerror (Function)
    error callback function

    ZipDirectoryEntry.prototype.exportFileEntry(fileEntry, onend[, onprogress, onerror])

    Export zipped content in a FileEntry object from this directory entry.

    Parameters:

    fileEntry (FileEntry)
    the FileEntry object
    onend (Function)
    success callback function returning the zipped content as parameter
    onprogress (Function)
    progress callback function returning an index (number) and a max value (number) as parameters
    onerror (Function)
    error callback function

    ZipDirectoryEntry.prototype.getChildByName(name)

    Get a ZipEntry child object given its filename.

    Parameters:

    name (string)
    the entry name

    Return

    ZipEntry
    the ZipEntry object