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

    Interface ZipWriterAddDataOptions

    Represents the options passed to ZipWriter#add.

    interface ZipWriterAddDataOptions {
        bufferedWrite?: boolean;
        comment?: string;
        compressionMethod?: number;
        crc32?: number;
        createTempStream?: () => TempStream | Promise<TempStream>;
        creationDate?: Date;
        dataDescriptor?: boolean;
        dataDescriptorSignature?: boolean;
        directory?: boolean;
        encrypted?: boolean;
        encryptionStrength?: 2 | 1 | 3;
        executable?: boolean;
        extendedTimestamp?: boolean;
        externalFileAttribute?: number;
        externalFileAttributes?: number;
        extraField?: Map<number, Uint8Array<ArrayBufferLike>>;
        gid?: number;
        internalFileAttribute?: number;
        internalFileAttributes?: number;
        keepOrder?: boolean;
        lastAccessDate?: Date;
        lastModDate?: Date;
        level?: number;
        localExtraField?: Map<number, Uint8Array<ArrayBufferLike>>;
        msdosAttributes?: {
            archive?: boolean;
            directory?: boolean;
            hidden?: boolean;
            readOnly?: boolean;
            system?: boolean;
        };
        msdosAttributesRaw?: number;
        msDosCompatible?: boolean;
        ntfsTimestamp?: boolean;
        offset?: number;
        passThrough?: boolean;
        password?: string;
        preventClose?: boolean;
        rawPassword?: Uint8Array<ArrayBufferLike>;
        setgid?: boolean;
        setuid?: boolean;
        signal?: AbortSignal;
        signature?: number;
        sticky?: boolean;
        supportZip64SplitFile?: boolean;
        transferStreams?: boolean;
        uid?: number;
        uncompressedSize?: number;
        unixExtraFieldType?: "infozip" | "unix";
        unixMode?: number;
        usdz?: boolean;
        useCompressionStream?: boolean;
        useUnicodeFileNames?: boolean;
        useWebWorkers?: boolean;
        version?: number;
        versionMadeBy?: number;
        zip64?: boolean;
        zipCrypto?: boolean;
        encodeText?(
            text: string,
            type: "filename" | "comment",
        ): Uint8Array<ArrayBufferLike> | undefined;
        onend?(computedSize: number): void | Promise<void>;
        onprogress?(progress: number, total: number): void | Promise<void>;
        onstart?(total: number): void | Promise<void>;
    }

    Hierarchy (View Summary)

    Index
    bufferedWrite?: boolean

    true to write entry data in a buffer before appending it to the zip file.

    bufferedWrite is automatically set to true when compressing more than one entry in parallel.

    false
    
    comment?: string

    The comment of the entry.

    It is a string, unlike the global comment passed to ZipWriter#close, because the encoding of the comment of an entry is recorded in the header by the general purpose bit 11 (see Appendix D - Language Encoding (EFS)), set by ZipWriterConstructorOptions#useUnicodeFileNames. Passing raw bytes here throws ERR_INVALID_ENTRY_COMMENT_TYPE instead of writing their textual representation.

    compressionMethod?: number

    The compression method (e.g. 8 for DEFLATE, 0 for STORE).

    crc32?: number

    The CRC-32 checksum of the content. This option is ignored if the ZipWriterConstructorOptions#passThrough option is not set to true.

    When the entry is AES-encrypted (see ZipWriterConstructorOptions#encrypted), setting this option marks the entry as AE-1 and stores the checksum in the entry headers, e.g. when copying an AE-1 entry read with the ZipReaderOptions#passThrough option. Otherwise, the entry is marked as AE-2 and the checksum fields are set to 0.

    createTempStream?: () => TempStream | Promise<TempStream>

    An async factory function that returns a TransformStream-like object ({ writable, readable }) used as a temporary buffer when entries are written in parallel.

    When provided, this replaces the default in-memory TransformStream buffer, allowing data to be stored externally (e.g. filesystem, OPFS, network). The writable side receives compressed entry data. The readable side is consumed when the entry is replayed into the final zip stream. The optional dispose method is called once the entry has been processed (on success, error, or abort) so a resource-backed buffer can release its resource.

    See createOPFSTempStream for a ready-made OPFS-backed implementation, createSyncAccessHandleTempStream for a faster worker-only variant, and createBlobTempStream for a Blob-backed one.

    The readable side is consumed only once the writable side has been closed, since the local header written before it holds the size and the CRC-32 of the entry. The object must therefore be able to hold a whole entry, either by buffering it like the default new TransformStream(undefined, undefined, { highWaterMark: Infinity }) does, or by draining it like the three implementations above do. A factory returning new TransformStream() deadlocks instead, its default queuing strategy holding a single chunk.

    creationDate?: Date

    The creation date.

    This option is ignored if the ZipWriterConstructorOptions#extendedTimestamp option is set to false.

    Unlike ZipWriterConstructorOptions#lastModDate, it has no default: the date is written only when the option is set, so that the entries do not carry a meaningless creation time.

    dataDescriptor?: boolean

    true to add a data descriptor.

    When set to false, the ZipWriterConstructorOptions#bufferedWrite option will automatically be set to true. It will be automatically set to false when it is undefined and the ZipWriterConstructorOptions#bufferedWrite option is set to true, or when the entry is a folder or an empty entry stored without compression or encryption, since the header can then carry the sizes and the CRC-32 directly. It will be automatically set to true when the ZipWriterConstructorOptions#zipCrypto option is set to true. Otherwise, the default value is true.

    dataDescriptorSignature?: boolean

    true to add the signature of the data descriptor.

    true
    
    directory?: boolean

    true if the entry is a directory.

    false
    
    encrypted?: boolean

    true to write encrypted data when passThrough is set to true.

    encryptionStrength?: 2 | 1 | 3

    The encryption strength (AES):

    • 1: 128-bit encryption key
    • 2: 192-bit encryption key
    • 3: 256-bit encryption key
    3
    
    executable?: boolean

    true if the entry is an executable file.

    false
    
    extendedTimestamp?: boolean

    true to store extended timestamp extra fields.

    When set to false, the maximum last modification date cannot exceed December 31, 2107 and the maximum accuracy is 2 seconds, dates being truncated to the whole second and odd seconds rounded up to the next even second.

    true
    
    externalFileAttribute?: number

    The external file attribute.

    externalFileAttributes?: number

    The external file attribute.

    When set explicitly, the value is written verbatim (including 0), unless unixMode, setuid, setgid or sticky is also set, in which case these options override the upper 16 bits while the lower 16 bits are preserved. When omitted, the value is derived from the other options (e.g. the MS-DOS directory attribute for folder entries, Unix default permissions when msDosCompatible is false).

    extraField?: Map<number, Uint8Array<ArrayBufferLike>>

    The extra field of the entry, written in the local file header and the central directory.

    gid?: number

    The Unix group id to write in the Unix extra field or as part of the external attributes.

    internalFileAttribute?: number

    The internal file attribute.

    internalFileAttributes?: number

    The internal file attribute.

    0
    
    keepOrder?: boolean

    true to keep the order of the entry physically in the zip file.

    When set to true, the use of web workers will be improved.

    true
    
    lastAccessDate?: Date

    The last access date.

    This option is ignored if the ZipWriterConstructorOptions#extendedTimestamp option is set to false.

    Unlike ZipWriterConstructorOptions#lastModDate, it has no default: the date is written only when the option is set, so that the entries do not carry a meaningless access time.

    lastModDate?: Date

    The last modification date.

    This option and the two below must be Date instances: a timestamp expressed in milliseconds, e.g. File#lastModified, and an invalid Date are both rejected with ERR_INVALID_DATE. An invalid Date used to be written as an entry carrying no timestamp at all.

    The current date.
    
    level?: number

    The level of compression.

    The minimum value is 0 and means that no compression is applied. The maximum value is 9.

    The native API CompressionStream does not support compression levels. Any value other than 6, its de facto level, disables useCompressionStream and compresses the data with the embedded implementation instead. Note that the compressed data produced at a given level can still vary between platforms. Set useCompressionStream to false to get deterministic output across platforms.

    6
    
    localExtraField?: Map<number, Uint8Array<ArrayBufferLike>>

    The extra field of the entry written only in the local file header.

    msdosAttributes?: {
        archive?: boolean;
        directory?: boolean;
        hidden?: boolean;
        readOnly?: boolean;
        system?: boolean;
    }

    When provided, MS-DOS attribute flags (boolean object) to write into external file attributes low byte.

    See ZipWriterConstructorOptions#msdosAttributesRaw for the platform this option selects and for the Unix metadata it leaves out of the entry.

    msdosAttributesRaw?: number

    When provided, the low 8-bit MS-DOS attributes to write into external file attributes. Must be an integer between 0 and 255.

    Setting this option or ZipWriterConstructorOptions#msdosAttributes selects the MS-DOS platform for the entry exactly as ZipWriterConstructorOptions#msDosCompatible does, and overrides that option when it is explicitly set to false. EntryMetaData#versionMadeBy then loses its Unix upper byte and no Unix mode is written, so the 0o100644 of a file entry and the 0o040755 of a folder entry are lost. What counts is that the option is provided, not its value: 0 and {} trigger it too.

    Setting any Unix metadata option, i.e. ZipWriterConstructorOptions#uid, ZipWriterConstructorOptions#gid, ZipWriterConstructorOptions#unixMode, ZipWriterConstructorOptions#unixExtraFieldType or ZipWriterAddDataOptions#executable, takes precedence and keeps the Unix attributes, with the MS-DOS attributes written into the low byte. ZipWriterConstructorOptions#externalFileAttributes is preserved as well, although the entry still declares the MS-DOS platform.

    msDosCompatible?: boolean

    true to write EntryMetaData#externalFileAttributes in MS-DOS format for folder entries.

    It also selects the MS-DOS platform for ZipWriterConstructorOptions#versionMadeBy and leaves the Unix attributes out of the entries. Setting any Unix metadata option, e.g. ZipWriterConstructorOptions#unixMode or ZipWriterAddDataOptions#executable, turns it back off, and setting ZipWriterConstructorOptions#msdosAttributesRaw or ZipWriterConstructorOptions#msdosAttributes turns it on, overriding an explicit false.

    false
    
    ntfsTimestamp?: boolean

    true to always store the NTFS extra field, false to never store it.

    By default, the NTFS extra field is stored only when it preserves information the extended timestamp extra field cannot represent: a last modification date outside its supported range, or explicit ZipWriterConstructorOptions#lastAccessDate or ZipWriterConstructorOptions#creationDate values.

    This option is ignored if the ZipWriterConstructorOptions#extendedTimestamp option is set to false.

    offset?: number

    The offset of the first entry in the zip file.

    passThrough?: boolean

    true to write the data as-is without compressing it and without crypting it.

    The data is never compressed, so the ZipWriterConstructorOptions#level option does not apply and is ignored. The ZipWriterAddDataOptions#compressionMethod option selects no codec either, it declares how the data is already compressed and is written as-is in the entry headers. It must be set, otherwise an ERR_UNDEFINED_COMPRESSION_METHOD error is thrown. The entries with no content, e.g. the directories, ignore this option entirely. Setting the ZipWriterConstructorOptions#password or the ZipWriterConstructorOptions#rawPassword option throws an ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH error, unless the ZipWriterConstructorOptions#encrypted option is set to true to declare that the data is already encrypted. In that case the password encrypts the other entries only, and the data written as-is keeps the password it was encrypted with, which is not verified.

    password?: string

    The password used to encrypt the content of the entry.

    When a password is set and the ZipWriterConstructorOptions#zipCrypto option is not set to true, the entry is encrypted in AES AE-2 format: the CRC-32 checksum of the content is stored as 0 so that the zip file reveals no information about the encrypted content. A stored checksum would allow an attacker to verify guessed content without knowing the password. The integrity of the data is guaranteed by the authentication code instead.

    preventClose?: boolean

    true to prevent closing of WritableWriter#writable.

    false
    
    rawPassword?: Uint8Array<ArrayBufferLike>

    The password used to encrypt the content of the entry (raw).

    setgid?: boolean

    true to set the setgid bit when writing the Unix mode.

    setuid?: boolean

    true to set the setuid bit when writing the Unix mode.

    signal?: AbortSignal

    The AbortSignal instance used to cancel the compression.

    signature?: number

    The signature (CRC32 checksum) of the content. This option is ignored if the ZipWriterConstructorOptions#passThrough option is not set to true.

    Use ZipWriterAddDataOptions#crc32 instead.

    sticky?: boolean

    true to set the sticky bit when writing the Unix mode.

    supportZip64SplitFile?: boolean

    false to never write disk numbers in zip64 data.

    true
    
    transferStreams?: boolean

    true to transfer stream ownership to web workers.

    true
    
    uid?: number

    The Unix owner id to write in the Unix extra field or as part of the external attributes.

    uncompressedSize?: number

    The uncompressed size of the entry. This option is ignored if the ZipWriterConstructorOptions#passThrough option is not set to true.

    unixExtraFieldType?: "infozip" | "unix"

    Which Unix extra field format to write when creating entries that include Unix metadata.

    • "infozip": Info-ZIP New Unix extra field (0x7875), storing variable-length uid/gid up to 32 bits.
    • "unix": Info-ZIP Unix extra field type 2 (0x7855), storing fixed 2-byte uid/gid (0..65535); a larger uid or gid is rejected. The Unix mode is not part of this field; it is written to the external file attributes.

    When ZipFS exports imported entries, their uid/gid are re-emitted as "infozip" regardless of the field type found in the imported zip file, unless this option is set explicitly.

    unixMode?: number

    The Unix mode (st_mode bits) to use when writing external attributes.

    The value includes the Unix file type, so it is also how a symbolic link is written: pass 0o120777 and use the path of the link target as the content of the entry. Extractors that support symbolic links, e.g. Info-ZIP unzip, then restore the entry as a link.

    A folder entry is always written with S_IFDIR (0o040000), replacing any file type carried by the value, so the same mode can be set once on the writer and reused for every entry. Any other entry keeps the file type it is given, and is written with S_IFREG (0o100000) when the value carries none. Set ZipWriterConstructorOptions#externalFileAttributes instead to write a mode with no file type.

    usdz?: boolean

    trueto produce zip files compatible with the USDZ specification: the data of the entries is aligned on 64-byte boundaries and stored uncompressed unless the ZipWriterConstructorOptions#level or ZipWriterAddDataOptions#compressionMethod options are set explicitly. Setting the ZipWriterConstructorOptions#password option throws an ERR_UNSUPPORTED_ENCRYPTION_USDZ error.

    false
    
    useCompressionStream?: boolean

    true to use the native API CompressionStream/DecompressionStream to compress/decompress data.

    When compressing, the native API is only used when level is undefined or equal to 6, see ZipWriterConstructorOptions#level.

    true
    
    useUnicodeFileNames?: boolean

    true to mark the file names as UTF-8 setting the general purpose bit 11 in the header (see Appendix D - Language Encoding (EFS)), false to mark the names as compliant with the original IBM Code Page 437.

    Note that this does not ensure that the file names are in the correct encoding.

    true
    
    useWebWorkers?: boolean

    true to use web workers to compress/decompress data in non-blocking background processes.

    true
    
    version?: number

    The "Version" field.

    versionMadeBy?: number

    The "Version made by" field, whose upper byte is the platform and lower byte the version of the specification.

    The platform is not taken from the value passed here. It is forced to Unix (3) when the entry carries Unix metadata, i.e. when ZipWriterConstructorOptions#uid, ZipWriterConstructorOptions#gid, ZipWriterConstructorOptions#unixMode or ZipWriterConstructorOptions#unixExtraFieldType is set, since Unix mode bits stored under another platform are ignored by the extractors. It is forced to MS-DOS (0) when ZipWriterConstructorOptions#msdosAttributes or ZipWriterConstructorOptions#msdosAttributesRaw is set. Only the lower byte of the value survives in both cases.

    768, i.e. 3 << 8, or 20 when ZipWriterConstructorOptions#msDosCompatible is set to true

    zip64?: boolean

    true to use Zip64 to store the entry.

    zip64 is automatically set to true when necessary (e.g. compressed data larger than 4GB or with unknown size).

    false
    
    zipCrypto?: boolean

    true to use the ZipCrypto algorithm to encrypt the content of the entry. Setting it to true will also set the ZipWriterConstructorOptions#dataDescriptor to true.

    It is not recommended to set zipCrypto to true because the ZipCrypto encryption can be easily broken.

    false
    
    • The function called for encoding the filename and the comment of the entry.

      Parameters

      • text: string

        The text to encode.

      • type: "filename" | "comment"

        The type of the encoded text, "filename" or "comment".

      Returns Uint8Array<ArrayBufferLike> | undefined

      The encoded text or undefined if the text should be encoded by zip.js.

    • The function called when ending compression/decompression.

      Parameters

      • computedSize: number

        The total number of bytes (computed).

      Returns void | Promise<void>

      An empty promise or undefined.

    • The function called during compression/decompression.

      Parameters

      • progress: number

        The current progress in bytes.

      • total: number

        The total number of bytes.

      Returns void | Promise<void>

      An empty promise or undefined.

    • The function called when starting compression/decompression.

      Parameters

      • total: number

        The total number of bytes.

      Returns void | Promise<void>

      An empty promise or undefined.