/** * Core ZIP extraction logic - shared between ZipParser and RemoteZipReader. * * This module provides unified functions for: * - Decrypting entry data (AES and ZipCrypto) * - Decompressing entry data * - Reading local file header * - CRC32 validation * * @module */ import { BinaryReader } from "../zip-spec/binary.js"; import type { ZipEntryInfo } from "../zip-spec/zip-entry-info.js"; /** * Local file header fixed size (30 bytes) */ export declare const LOCAL_HEADER_FIXED_SIZE = 30; /** * Options for extracting entry data */ export interface ExtractCoreOptions { /** Password for encrypted entries */ password?: string | Uint8Array; /** Whether to validate CRC32 checksum after extraction */ checkCrc32?: boolean; /** * Whether to validate that the decompressed size matches the declared size. * This is a security feature to detect ZIP bombs and corrupted archives. * When enabled, extraction will abort early if too many bytes are produced. * @default true */ validateEntrySizes?: boolean; } /** * Process compressed (and possibly encrypted) entry data to get the final content. * * This is the core extraction logic used by both ZipParser and RemoteZipReader. * * @param entry - Entry metadata * @param compressedData - Raw compressed (and possibly encrypted) data from the ZIP * @param password - Optional password for decryption * @param checkCrc32 - Whether to validate CRC32 checksum (default: false) * @param validateEntrySizes - Whether to validate decompressed size matches declared size (default: true) * @returns Decompressed entry content */ export declare function processEntryData(entry: ZipEntryInfo, compressedData: Uint8Array, password?: string | Uint8Array, checkCrc32?: boolean, validateEntrySizes?: boolean): Promise; /** * Process compressed (and possibly encrypted) entry data synchronously. * * Note: AES-encrypted files cannot be processed synchronously because * the Web Crypto API is async. Use processEntryData() instead. * * @param entry - Entry metadata * @param compressedData - Raw compressed (and possibly encrypted) data from the ZIP * @param password - Optional password for decryption * @param validateEntrySizes - Whether to validate decompressed size matches declared size (default: true) * @returns Decompressed entry content * @throws Error if the entry uses AES encryption */ export declare function processEntryDataSync(entry: ZipEntryInfo, compressedData: Uint8Array, password?: string | Uint8Array, validateEntrySizes?: boolean): Uint8Array; /** * Process entry data as an async iterable of output chunks. * * This avoids buffering the full output in memory for STORE/DEFLATE entries. * * Note: AES-encrypted entries cannot be truly streamed because HMAC verification * requires the full ciphertext; this function falls back to buffering for AES. */ export declare function processEntryDataStream(entry: ZipEntryInfo, compressedData: AsyncIterable, options?: ExtractCoreOptions & { signal?: AbortSignal; }): AsyncIterable; /** * Read the data offset from a local file header. * * The data offset is the position after the local file header where * the actual compressed data begins. * * @param reader - Binary reader positioned at the local file header * @param expectedOffset - Expected offset (for error messages) * @returns Offset where the compressed data starts */ export declare function readLocalHeaderDataOffset(reader: BinaryReader, expectedOffset: number): number; /** * Read compressed data for an entry from a buffer. * * @param data - Full ZIP buffer * @param entry - Entry to read * @returns Compressed data for the entry */ export declare function readEntryCompressedData(data: Uint8Array, entry: ZipEntryInfo): Uint8Array;