/** * ZIP file format encoder (single-buffer output) * * Implements ZIP file structure according to PKWARE's APPNOTE.TXT specification * https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT * * This module focuses on producing a complete ZIP as a single Uint8Array. * For true streaming (push chunks while reading sources), use `zip()` / `ZipArchive.stream()`. */ import { type CompressOptions } from "../compression/compress.js"; import { type ZipEncryptionMethod } from "../crypto/index.js"; import { type ZipStringEncoding } from "../shared/text.js"; import { type ZipTimestampMode } from "../zip-spec/timestamps.js"; import { type ZipPathOptions } from "../zip-spec/zip-path.js"; import type { Zip64Mode } from "../zip-spec/zip-records.js"; /** * ZIP file entry */ export interface ZipEntry { /** File name (can include directory path, use forward slashes) */ name: string; /** File data (will be compressed unless level=0) */ data: Uint8Array; /** Optional per-entry compression level override */ level?: number; /** File modification time (optional, defaults to current time) */ modTime?: Date; /** Optional access time (used only when timestamps mode supports it). */ atime?: Date; /** Optional metadata change time (used only when timestamps mode supports it). */ ctime?: Date; /** Optional creation time (used by NTFS timestamps mode). */ birthTime?: Date; /** File comment (optional) */ comment?: string; /** Optional string encoding for this entry name/comment. */ encoding?: ZipStringEncoding; /** Per-entry encryption method override */ encryptionMethod?: ZipEncryptionMethod; /** Per-entry password override */ password?: string | Uint8Array; /** * Unix mode/permissions for this entry. * Accepts either a full `stat.mode` (includes file type bits), or just permission bits. */ mode?: number; /** Optional MS-DOS attributes (low 8 bits). */ msDosAttributes?: number; /** Advanced override for the central directory `version made by` field. */ versionMadeBy?: number; /** * External file attributes (optional). * For Unix symlinks, use: ((mode << 16) | 0x20) * where mode is typically 0o120777 for symlinks. */ externalAttributes?: number; } export type { ZipRawEntry } from "./raw-entry.js"; import { type ZipRawEntry } from "./raw-entry.js"; export type ZipBuildEntry = ZipEntry | ZipRawEntry; type ZipPathOptionValue = false | ZipPathOptions; /** * ZIP encoder options */ export interface ZipOptions extends CompressOptions { /** ZIP file comment (optional) */ comment?: string; /** * Default modification time for entries that don't specify `modTime`. * * If you need stable output across runs, either pass this explicitly or use `reproducible: true`. */ modTime?: Date; /** * If true, bias defaults toward reproducible output: * - default `modTime` becomes 1980-01-01 00:00:00 (local time) * - default `timestamps` becomes "dos" (no UTC extra field) */ reproducible?: boolean; /** * If true, entries are written in their original input order. * If false (default), entries are sorted alphabetically by name. */ noSort?: boolean; /** * Max number of entries to compress concurrently in `createZip()`. * This helps avoid zlib threadpool saturation / memory spikes with many files. * * Defaults to 4. */ concurrency?: number; /** Optional string encoding for entry names/comments and archive comment. */ encoding?: ZipStringEncoding; /** * If true (default), automatically STORE incompressible data. * If false, always follow `level` (DEFLATE when level > 0). */ smartStore?: boolean; /** * Timestamp writing strategy. * - "dos": only write DOS date/time fields (smallest output) * - "dos+utc": also write UTC mtime in 0x5455 extra field */ timestamps?: ZipTimestampMode; /** * ZIP64 mode: * - "auto" (default): write ZIP64 only when required by limits (e.g. >65535 entries). * - true: force ZIP64 structures even for small archives (less legacy compatibility). * - false: forbid ZIP64; throws if ZIP64 is required. */ zip64?: Zip64Mode; /** * Encryption method for all entries: * - "none" (default): no encryption * - "zipcrypto": Traditional PKWARE encryption (weak, for compatibility) * - "aes-128", "aes-192", "aes-256": WinZip AES encryption (recommended) */ encryptionMethod?: ZipEncryptionMethod; /** * Password for encryption. Required when encryptionMethod is not "none". */ password?: string | Uint8Array; /** * Optional entry name normalization. * - `false` (default): do not modify entry names. * - `ZipPathOptions`: normalize each entry name before writing. */ path?: ZipPathOptionValue; } /** * Create a ZIP file from entries (async) */ export declare function createZip(entries: ZipBuildEntry[], options?: ZipOptions): Promise; /** * Create a ZIP file from entries (sync) * * This is supported in both Node.js and browser builds. * Note: AES encryption is not supported in sync mode. */ export declare function createZipSync(entries: ZipBuildEntry[], options?: ZipOptions): Uint8Array;