/** * Pure Uint8Array-based ZIP parser * Works in both Node.js and browser environments * No dependency on Node.js stream module */ import type { ZipStringEncoding } from "../shared/text.js"; import type { ZipEntryInfo } from "../zip-spec/zip-entry-info.js"; export type { ZipEntryInfo }; /** * ZIP parsing options */ export interface ZipParseOptions { /** Whether to decode file names as UTF-8 (default: true) */ decodeStrings?: boolean; /** Optional string encoding for legacy (non-UTF8) names/comments. */ encoding?: ZipStringEncoding; /** Password for encrypted entries */ password?: string | Uint8Array; } /** * Extraction options with optional password support. */ export interface ExtractOptions { /** Password for encrypted entries */ password?: string | Uint8Array; } /** * High-level ZIP parser class */ export declare class ZipParser { private data; private entries; private entryMap; private password?; private archiveComment; constructor(data: Uint8Array | ArrayBuffer, options?: ZipParseOptions); /** * Set the password for encrypted entries. */ setPassword(password: string | Uint8Array | undefined): void; /** * Get all entries in the ZIP file */ getEntries(): ZipEntryInfo[]; /** * Get entry by path */ getEntry(path: string): ZipEntryInfo | undefined; /** * Get a zero-copy view of the raw (compressed) entry payload. * * Notes: * - This returns the bytes as stored in the ZIP (compressed and possibly encrypted). * - The returned Uint8Array is a view into the original ZIP buffer. * - This does NOT include the local file header, extra field, or data descriptor. */ getRawCompressedData(path: string): Uint8Array | null; /** * Get raw (compressed) payload together with its parsed entry info. */ getRawEntry(path: string): { info: ZipEntryInfo; compressedData: Uint8Array; } | null; /** * Check if entry exists */ hasEntry(path: string): boolean; /** * Get the number of child entries in a directory. * * Returns the count of entries whose paths start with the directory prefix, * excluding the directory entry itself. For non-directory entries, returns 0. * * @param path - Directory path (with or without trailing slash) * @returns Number of child entries */ childCount(path: string): number; /** * Get the archive comment. */ getZipComment(): string; /** * Check if the archive contains encrypted entries */ hasEncryptedEntries(): boolean; /** * Get all encrypted entries */ getEncryptedEntries(): ZipEntryInfo[]; /** * List all file paths */ listFiles(): string[]; /** * Extract a single file (async) * @param path - File path within the archive * @param password - Optional password for this entry (overrides constructor password) */ extract(path: string, password?: string | Uint8Array): Promise; /** * Extract a single file (sync) * * Note: AES-encrypted files cannot be extracted synchronously. * Use the async extract() method for AES-encrypted files. * * @param path - File path within the archive * @param password - Optional password for this entry (overrides constructor password) */ extractSync(path: string, password?: string | Uint8Array): Uint8Array | null; /** * Extract all files (async) * @param password - Optional password for encrypted entries (overrides constructor password) */ extractAll(password?: string | Uint8Array): Promise>; /** * Extract all files (sync) * Returns object with file paths as keys and Uint8Array content as values * * Note: AES-encrypted files cannot be extracted synchronously. * Use the async extractAll() method if the archive contains AES-encrypted files. * * @param password - Optional password for encrypted entries (overrides constructor password) */ extractAllSync(password?: string | Uint8Array): Record; /** * Iterate over entries with async callback * @param callback - Callback for each entry * @param password - Optional password for encrypted entries (overrides constructor password) */ forEach(callback: (entry: ZipEntryInfo, getData: () => Promise) => Promise, password?: string | Uint8Array): Promise; }