@zip.js/zip.js
    Preparing search index...

    Class ZipFS

    Hierarchy

    • Pick<
          ZipDirectoryEntry,
          | "getChildByName"
          | "getChildren"
          | "addDirectory"
          | "addText"
          | "addBlob"
          | "addData64URI"
          | "addUint8Array"
          | "addHttpContent"
          | "addReadable"
          | "addFile"
          | "addFileSystemEntry"
          | "addFileSystemHandle"
          | "importBlob"
          | "importData64URI"
          | "importUint8Array"
          | "importHttpContent"
          | "importReadable"
          | "importZip"
          | "exportBlob"
          | "exportData64URI"
          | "exportUint8Array"
          | "exportWritable"
          | "exportFileSystemHandle"
          | "exportZip"
          | "getExportedSize"
          | "isPasswordProtected"
          | "checkPassword",
      >
      • ZipFS
    Index
    • Returns ZipFS

    children: ZipEntry[]

    The children of the root directory.

    entries: (ZipEntry | null)[]

    The array of all the ZipEntry instances indexed by ZipEntry#id.

    The root directory.

    • Writes the entry and its descendants into a directory as files and sub-directories via the File System Access API (e.g. the Origin Private File System). Files are streamed and directories are merged into the target; colliding files are overwritten. This is the inverse of ZipDirectoryEntry#addFileSystemHandle.

      If an entry cannot be written, the original error is rethrown unmodified as an EntryError, whose EntryError#entryName is the name of the entry that failed, relative to this entry.

      The export is not atomic and nothing is rolled back, because the target is merged into rather than replaced: a file that already existed cannot be restored once overwritten. On failure the target is left as follows, and EntryError#exportedEntryNames lists the files that completed:

      • files written before the failure are left in place, complete and valid;
      • a file whose write started but did not finish is left empty, because it is created before its content is streamed; this includes the entry that failed and, with concurrent, every entry cancelled alongside it;
      • files that already existed in the target keep their previous content unless they were overwritten in full;
      • entries not started yet are missing, as are the directories that would have held them.

      Running the same export again is the supported way to recover, since directories are merged and files are overwritten.

      Parameters

      Returns Promise<FileSystemDirectoryHandle>

      A promise resolving to the target FileSystemDirectoryHandle instance.

      An entry flagged as a symbolic link by EntryMetaData#symlink is written as a regular file whose content is the path of the link target, because the File System Access API cannot create symbolic links.

    • Creates a zip file via a custom Writer instance containing the entry and its descendants

      Parameters

      Returns Promise<unknown>

      A promise resolving to the data.

    • Gets the children of the directory

      Parameters

      Returns ZipEntry[]

      The array of ZipEntry instances.

      The returned array is a snapshot taken when the method is called: entries added or removed afterwards are not reflected, and an entry removed while the array is being iterated is still present but detached from the filesystem.

      With recursive, the descendants are ordered level by level, i.e. the children of a directory come before the children of its subdirectories, like the result of readdir(path, { recursive: true }) in Node.js. This is also the order in which {@link ZipDirectoryEntry}#export*() writes them.

      Unlike ZipFS#entries, the directory itself is not included and removed entries leave no empty slot.

    • Computes the exact size in bytes of the zip file that export*() would produce for the entry and its descendants, without reading or compressing any data.

      Pass the same options object that will be passed to the export method, otherwise the result will not match. The size is only determinable when every descendant is stored (i.e. level is set to 0) or passed through, and has a known size; ERR_UNDETERMINED_SIZE is thrown otherwise. Encryption does not prevent it, the overhead of ZipCrypto and AES being fixed.

      The intended use is setting the Content-Length header of a zip file streamed over HTTP.

      Parameters

      Returns Promise<number>

      A promise resolving to the size in bytes.

      Entries added with ZipDirectoryEntry#addReadable never have a known size, and entries added with ZipDirectoryEntry#addHttpContent only get one once their content has been read. The returned size assumes a single output file, it does not apply to split zip files.

      ERR_UNDETERMINED_SIZE is also thrown when the size depends on the order in which the entries are physically written, which the buffered write path only determines at write time. This happens when usdz is set, since the alignment padding depends on the offset of each entry, and when the archive exceeds 4GB, since the offsets recorded in the central directory are then extended to 64 bits. Passing bufferedWrite: false makes both determinable again, as does exporting a directory whose children are all files. It is thrown as well when signCentralDirectory is set, the length of the signature being unknown until it is computed.

      ERR_UNDETERMINED_SIZE if the size cannot be determined.

    • Extracts a zip file provided via a custom Reader instance or a ZipReader instance into the entry

      Parameters

      Returns Promise<[ZipEntry]>

      The filename of each entry is split into path components to build the tree of entries. Empty components and "." components are ignored, so "a//b.txt", "./a/b.txt" and "a/./b.txt" all produce the same "a/b.txt" entry. Filenames are normalized and validated beforehand, see GetEntriesOptions#normalizeFilename and GetEntriesOptions#filenameValidation.

      The directories created that way are navigable like any other entry but are not written back when the tree is exported: only the directories carried by the source zip file and the ones created with ZipDirectoryEntry#addDirectory are written. A zip file storing no directory entry therefore round-trips to a zip file storing no directory entry, instead of gaining one entry per path component.

      Passing a ZipReader instance is the way to read the data of the zip file itself, e.g. its ZipReader#prependedData or its ZipReader#comment property, since the instance created otherwise is not exposed. Its options are used as defaults for the options passed here, and it must not have read its entries yet when it is created over a ReadableStream instance, which can only be read once.