/** * Shared ZIP format constants, public types, and internal helpers. * * Format reference: PKWARE APPNOTE.TXT (ZIP File Format Specification). * Section numbers in comments refer to APPNOTE 6.3.x. */ /** Compression method 0 — stored (no compression). APPNOTE 4.4.5. */ export declare const ZIP_METHOD_STORE = 0; /** Compression method 8 — deflate. APPNOTE 4.4.5. */ export declare const ZIP_METHOD_DEFLATE = 8; /** Local file header signature "PK\x03\x04". */ export declare const SIG_LOCAL_FILE_HEADER = 67324752; /** Central directory file header signature "PK\x01\x02". */ export declare const SIG_CENTRAL_FILE_HEADER = 33639248; /** End of central directory signature "PK\x05\x06". */ export declare const SIG_EOCD = 101010256; /** ZIP64 end of central directory record signature "PK\x06\x06". */ export declare const SIG_ZIP64_EOCD = 101075792; /** ZIP64 end of central directory locator signature "PK\x06\x07". */ export declare const SIG_ZIP64_LOCATOR = 117853008; /** Data descriptor signature "PK\x07\x08" (optional in the wild). */ export declare const SIG_DATA_DESCRIPTOR = 134695760; /** General purpose bit 3 — sizes/CRC live in a trailing data descriptor. */ export declare const FLAG_DATA_DESCRIPTOR = 8; /** General purpose bit 11 — file name and comment are UTF-8. */ export declare const FLAG_UTF8 = 2048; /** Extra field header ID for the ZIP64 extended information field. */ export declare const EXTRA_ID_ZIP64 = 1; export declare const MAX_U16 = 65535; export declare const MAX_U32 = 4294967295; /** * Fixed default DOS date: 1980-01-01 (day 1, month 1, year offset 0). * Used for all written entries unless overridden — `save()` output must be * deterministic (CONTRACTS.md §0.3), so we never read the clock. */ export declare const DEFAULT_DOS_DATE = 33; /** Fixed default DOS time: 00:00:00. */ export declare const DEFAULT_DOS_TIME = 0; /** * Default cap on the declared uncompressed/compressed size ratio per entry * (zip bomb guard). Deflate cannot legitimately exceed ~1032:1, so 1200 never * rejects a genuine archive while rejecting the absurd ratios bombs rely on. */ export declare const DEFAULT_MAX_COMPRESSION_RATIO = 1200; /** * Immutable metadata for one archive entry, sourced from the central * directory record (authoritative over the local header, including for * data-descriptor entries whose local sizes/CRC are zero). ZIP64 extra-field * values are already folded in. APPNOTE 4.3.12. */ export interface ZipEntryInfo { /** Entry name exactly as stored, decoded as UTF-8, '/'-separated. */ readonly name: string; /** 0 = store, 8 = deflate. Other methods fail on `read()`, not on open. */ readonly compressionMethod: number; /** CRC-32 of the uncompressed data (unsigned 32-bit). */ readonly crc32: number; /** Compressed byte length (from ZIP64 extra when present). */ readonly compressedSize: number; /** Uncompressed byte length (from ZIP64 extra when present). */ readonly uncompressedSize: number; /** General-purpose bit flags (bit 3 = data descriptor, bit 11 = UTF-8). */ readonly generalPurposeFlags: number; /** Last-modification time in DOS format, verbatim. */ readonly lastModTime: number; /** Last-modification date in DOS format, verbatim. */ readonly lastModDate: number; /** "Version made by" field, verbatim. */ readonly versionMadeBy: number; /** "Version needed to extract" field, verbatim. */ readonly versionNeeded: number; /** Internal file attributes, verbatim. */ readonly internalAttributes: number; /** External file attributes, verbatim. */ readonly externalAttributes: number; /** Central-directory extra field, verbatim bytes (may be empty). */ readonly extraField: Uint8Array; /** Entry comment decoded as UTF-8 (empty string when absent). */ readonly comment: string; /** True when any field of this entry required a ZIP64 extra record. */ readonly isZip64: boolean; /** Absolute byte offset of the local file header in the source archive. */ readonly localHeaderOffset: number; } /** * Everything required to copy an entry into a new archive without * recompression: central-directory metadata plus the raw (still compressed) * data stream and the local header's extra field. */ export interface ZipRawEntry { /** Central-directory metadata for the entry. */ readonly info: ZipEntryInfo; /** * The entry's data stream exactly as stored in the source archive — * compressed if the entry is deflated, verbatim if stored. No headers, * no data descriptor. */ readonly compressedData: Uint8Array; /** Local file header extra field, verbatim bytes (may be empty). */ readonly localExtraField: Uint8Array; } /** Options for `ZipWriter.add`. */ export interface ZipAddOptions { /** * Compress with deflate-raw (default true). Pass false to store * uncompressed (used e.g. for already-compressed media parts). */ compress?: boolean; /** * DOS-format modification time. Default: fixed value for 1980-01-01 * 00:00:00 so that output archives are deterministic. */ lastModTime?: number; /** DOS-format modification date. Default: see `lastModTime`. */ lastModDate?: number; } /** Options for `ZipReader.open`. */ export interface ZipReaderOptions { /** * Zip bomb guard: maximum allowed declared uncompressed/compressed size * ratio per entry (default `DEFAULT_MAX_COMPRESSION_RATIO`). Entries whose * central directory declares a higher ratio cause `open` to throw. Pass * `Infinity` to disable. */ maxCompressionRatio?: number; /** * Aggregate zip bomb guard: maximum allowed **sum** of declared * uncompressed sizes across all central directory records. Defaults to * `maxCompressionRatio × archive byte length`, which no genuine archive * can exceed (deflate tops out near 1032:1 per entry) while overlapping- * entry bombs — many central records sharing one data region — blow far * past it. `open` throws when the total exceeds this budget. Pass * `Infinity` to disable. */ maxTotalUncompressedSize?: number; } /** Create a module-prefixed error (CONTRACTS.md §0.3). */ export declare function zipError(message: string): Error; /** * Zip-slip defense: reject entry names that could escape an extraction root. * Rejected: empty names, NUL bytes, absolute paths (`/…` or `\…`), Windows * drive prefixes (`C:…`), and any `..` traversal that climbs above the root. * Backslashes are tolerated as separators (old .NET Framework * System.IO.Compression writes `sub\file.xml`) but count in the escape check. */ export declare function validateEntryName(name: string): void; /** Concatenate byte chunks. `total`, when known, avoids a second length pass. */ export declare function concatBytes(chunks: readonly Uint8Array[], total?: number): Uint8Array; /** * Push `data` through a CompressionStream/DecompressionStream and collect the * output. When `limit` is set, throws as soon as the output exceeds it (guards * memory while inflating: never materialize more than the declared size). */ export declare function pipeThrough(data: Uint8Array, transform: { readable: ReadableStream; writable: WritableStream; }, limit?: number): Promise; /** * Find one extra field by header ID and return its data bytes (APPNOTE 4.5). * Returns undefined when absent or when the remaining bytes are malformed. */ export declare function findExtraField(extra: Uint8Array, headerId: number): Uint8Array | undefined; /** * Return `extra` with every field of the given header ID removed; all other * fields (and any malformed tail) are kept byte-verbatim. Used to strip stale * ZIP64 fields before the writer regenerates them for the new layout. */ export declare function stripExtraField(extra: Uint8Array, headerId: number): Uint8Array; /** Read an unsigned 64-bit little-endian value as a JS number (throws above 2^53−1). */ export declare function readU64(view: DataView, offset: number): number; /** Write an unsigned 64-bit little-endian value from a JS number. */ export declare function writeU64(view: DataView, offset: number, value: number): void; /** True when every code unit is ASCII (name can be written without flag bit 11). */ export declare function isAscii(text: string): boolean; //# sourceMappingURL=common.d.ts.map