/** * Shared ZIP parsing primitives. * * This module contains pure functions for parsing EOCD, ZIP64 EOCD, and Central Directory. * Used by both `ZipParser` (in-memory) and `RemoteZipReader` (random-access). */ import { type ZipStringEncoding, type ZipStringCodec } from "../shared/text.js"; import { BinaryReader } from "./binary.js"; import type { ZipEntryInfo } from "./zip-entry-info.js"; /** Minimum EOCD size (22 bytes fixed + 0-byte comment) */ export declare const EOCD_MIN_SIZE = 22; /** Maximum comment size (2^16 - 1) */ export declare const EOCD_MAX_COMMENT_SIZE = 65535; /** Maximum bytes to search for EOCD signature */ export declare const EOCD_MAX_SEARCH_SIZE: number; /** ZIP64 EOCD Locator size */ export declare const ZIP64_EOCD_LOCATOR_SIZE = 20; /** * Parsed End of Central Directory (EOCD) information. */ export interface EOCDInfo { diskNumber: number; centralDirDisk: number; entriesOnDisk: number; totalEntries: number; centralDirSize: number; centralDirOffset: number; } /** * Parsed ZIP64 End of Central Directory information. */ export interface ZIP64EOCDInfo { entriesOnDisk: bigint; totalEntries: bigint; centralDirSize: bigint; centralDirOffset: bigint; } /** * Combined EOCD parse result. */ export interface EOCDParseResult { eocd: EOCDInfo; zip64Eocd: ZIP64EOCDInfo | null; comment: string; } /** * Options for parsing Central Directory entries. */ export interface CentralDirectoryParseOptions { /** Whether to decode file names as UTF-8 (default: true) */ decodeStrings?: boolean; /** Optional string encoding for legacy (non-UTF8) names/comments. */ encoding?: ZipStringEncoding; } /** * Find EOCD signature by searching backwards in a buffer. * * @param data - Buffer to search (should be the tail of the ZIP file) * @param validate - If true, validates the EOCD by checking comment length matches remaining bytes * @returns Offset within the buffer, or -1 if not found */ export declare function findEOCDSignature(data: Uint8Array, validate?: boolean): number; /** * Find ZIP64 EOCD Locator signature. * * @param data - Buffer containing the locator (should be 20 bytes before EOCD) * @param eocdOffset - Offset of EOCD within the buffer * @returns Offset within the buffer, or -1 if not found */ export declare function findZIP64EOCDLocator(data: Uint8Array, eocdOffset: number): number; /** * Parse EOCD from a buffer at the given offset. * * @param data - Buffer containing EOCD * @param offset - Offset of EOCD within the buffer * @param decodeStrings - Whether to decode the comment as UTF-8 * @returns Parsed EOCD info and comment */ export declare function parseEOCD(data: Uint8Array, offset: number, decodeStrings?: boolean, decoder?: Pick): { eocd: EOCDInfo; comment: string; }; /** * Parse ZIP64 EOCD Locator and return the offset of ZIP64 EOCD. * * @param data - Buffer containing the locator * @param offset - Offset of locator within the buffer * @returns ZIP64 EOCD file offset, or -1 if invalid */ export declare function parseZIP64EOCDLocator(data: Uint8Array, offset: number): number; /** * Parse ZIP64 EOCD. * * @param data - Buffer containing ZIP64 EOCD * @param offset - Offset within the buffer * @returns Parsed ZIP64 EOCD info, or null if invalid signature */ export declare function parseZIP64EOCD(data: Uint8Array, offset: number): ZIP64EOCDInfo | null; /** * Apply ZIP64 values to EOCD if standard values are maxed out. * * Mutates the provided `eocd` object. */ export declare function applyZIP64ToEOCD(eocd: EOCDInfo, zip64: ZIP64EOCDInfo): void; /** * Parse a single Central Directory entry from a BinaryReader. * * The reader should be positioned at the start of the entry (after signature validation). * After this call, the reader is positioned at the next entry (or end of CD). * * @param reader - BinaryReader positioned after the CD header signature * @param decodeStrings - Whether to decode strings as UTF-8 * @returns Parsed entry info */ export declare function parseCentralDirectoryEntry(reader: BinaryReader, decodeStrings: boolean, decoder?: Pick): ZipEntryInfo; /** * Parse all Central Directory entries from a buffer. * * @param data - Buffer containing the entire Central Directory * @param totalEntries - Expected number of entries * @param options - Parse options * @returns Array of parsed entries */ export declare function parseCentralDirectory(data: Uint8Array, totalEntries: number, options?: CentralDirectoryParseOptions): ZipEntryInfo[]; /** * Parse all Central Directory entries from a buffer starting at a specific offset. * * @param data - Buffer containing the Central Directory * @param offset - Offset within the buffer where CD starts * @param totalEntries - Expected number of entries * @param options - Parse options * @returns Array of parsed entries */ export declare function parseCentralDirectoryAt(data: Uint8Array, offset: number, totalEntries: number, options?: CentralDirectoryParseOptions): ZipEntryInfo[]; /** * Parse a complete ZIP archive from an in-memory buffer. * * This is a convenience function that handles EOCD + ZIP64 + Central Directory parsing. * * @param data - Complete ZIP file buffer * @param options - Parse options * @returns Parsed entries and archive comment */ export declare function parseZipArchiveFromBuffer(data: Uint8Array, options?: CentralDirectoryParseOptions): { entries: ZipEntryInfo[]; comment: string; };