/** * @copyright Sister Software. * @license AGPL-3.0 * @author Teffen Ellis, et al. * @file Zip readers, in two flavours — buffer-in for archives already in memory, path-in for archives on disk. * * {@link extractZip} and {@link extractSingleFileZip} take the whole archive as a `Buffer`, which is the right shape * when a client has just downloaded one (`bdc/sdk/download.ts`) and the wrong shape for anything sizable: adm-zip * holds the archive AND the decompressed member resident at once. The national address dumps under * `$MAILWOMAN_DATA_ROOT` are 0.5–2.9 GB compressed and up to 9 GB unpacked, so the path-in readers below stream — * yauzl seeks the central directory over a file handle and inflates one member on demand, at constant memory * regardless of archive size. * * The path-in readers also handle ZIP64, which the dumps need: a member above 4 GB parks `0xFFFFFFFF` in the 32-bit * size and offset slots and carries the real values in the entry's extra field. */ import ADMZip from "adm-zip"; import type { PathBuilderLike } from "path-ts"; export type ZipEntryContentPair = [entry: ADMZip.IZipEntry, content: Buffer]; /** * Extract the contents of a zip file. * * @category Files * @internal */ export declare function extractZip(data: ArrayBuffer | Buffer): Map; /** * Extract the contents of a zip file and return the first entry. */ export declare function extractSingleFileZip(data: ArrayBuffer | Buffer): Promise; /** * Names a member of an archive, either exactly or by pattern. * * A pattern matches the FIRST entry whose full archive-internal path tests true, in central-directory order. */ export type ZipEntrySelector = string | RegExp; /** * One archive member, as reported by the central directory. * * @category Files */ export interface ZipEntryInfo { /** * The archive-internal path, e.g. `it/countrywide.csv`. Directory entries keep their trailing slash. */ name: string; compressedSize: number; uncompressedSize: number; } /** * List an archive's members without decompressing any of them. * * @category Files */ export declare function listZipEntries(archivePath: PathBuilderLike): Promise; /** * Stream one member's decompressed bytes out of an archive on disk. * * Nothing beyond the central directory and the inflate window is held in memory, so this is bounded by the consumer * rather than by the member's size. A consumer that stops early — a `take`, a `break` — destroys the member stream and * closes the archive on the way out. * * @category Files * @throws If no member matches `selector`. */ export declare function readZipEntry(archivePath: PathBuilderLike, selector: ZipEntrySelector): AsyncGenerator; /** * Write one member's decompressed bytes to `destinationPath`. * * @category Files * * @returns The number of bytes written, as the central directory reports them. * @throws If no member matches `selector`. */ export declare function extractZipEntry(archivePath: PathBuilderLike, selector: ZipEntrySelector, destinationPath: PathBuilderLike): Promise; export interface ExtractZipEntriesOptions { /** * Which members to write. Omit for every member. */ selector?: ZipEntrySelector; /** * Write each member under its basename rather than its archive-internal path, flattening the tree — `unzip -j`. * * The shapefile archives this exists for carry their siblings in one directory, and the readers downstream expect * them flat. */ flatten?: boolean; } /** * Extract members of an archive into `destinationDirectory`. * * Directory entries are skipped; a nested path is created as needed unless `flatten` is set. Members stream one at a * time, so this is bounded by the largest member rather than by the archive. * * @category Files * * @returns The archive-internal names of everything written, in central-directory order. */ export declare function extractZipEntries(archivePath: PathBuilderLike, destinationDirectory: PathBuilderLike, { selector, flatten }?: ExtractZipEntriesOptions): Promise; /** * Verify every member's CRC-32 against the value its central-directory header claims — what `unzip -t` is for. * * This is a corruption check on a download, so it decompresses everything and keeps nothing; the archive is read one * member at a time and the checksum is folded chunk by chunk, so memory is bounded by the inflate window. * * The CRC is computed here rather than delegated to yauzl's `validateCrc32`, which asserts `Cannot validate CRC32 for * uncompressed data` on a STORED member — and a corrupt stored member is precisely what this is meant to catch. Folding * it locally covers both storage methods with one path. * * @category Files * * @returns The number of members checked. @throws If the archive is unreadable, or any member's checksum or length * disagrees with its header. */ export declare function verifyZipIntegrity(archivePath: PathBuilderLike): Promise; //# sourceMappingURL=zip.d.ts.map