Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions types/yauzl/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ export class ZipFile extends EventEmitter {
uncompressedSize: number | null,
callback: (err: Error | null, stream: Readable) => void,
): void;
openReadStreamPromise(entry: Entry, options?: ZipFileOptions): Promise<Readable>;
readLocalFileHeaderPromise(entry: Entry, options: { minimal: true }): Promise<{ fileDataStart: number }>;
readLocalFileHeaderPromise(entry: Entry, options?: { minimal?: boolean }): Promise<LocalFileHeader>;
openReadStreamLowLevelPromise(
fileDataStart: number,
compressedSize: number,
relativeStart: number,
relativeEnd: number,
decompress: boolean,
uncompressedSize: number | null,
): Promise<Readable>;
eachEntry(): AsyncIterableIterator<Entry>;
close(): void;
readEntry(): void;
}
Expand Down Expand Up @@ -161,6 +173,14 @@ export function fromRandomAccessReader(
totalSize: number,
callback: (err: Error | null, zipfile: ZipFile) => void,
): void;
export function openPromise(path: string, options?: Options): Promise<ZipFile>;
export function fromFdPromise(fd: number, options?: Options): Promise<ZipFile>;
export function fromBufferPromise(buffer: Buffer, options?: Options): Promise<ZipFile>;
export function fromRandomAccessReaderPromise(
reader: RandomAccessReader,
totalSize: number,
options?: Options,
): Promise<ZipFile>;
/** @deprecated Use `entry.getLastModDate()` instead. */
export function dosDateTimeToDate(date: number, time: number): Date;
export function validateFileName(fileName: string): string | null;
Expand Down
2 changes: 1 addition & 1 deletion types/yauzl/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/yauzl",
"version": "3.3.9999",
"version": "3.4.9999",
"projects": [
"https://github.com/thejoshwolfe/yauzl"
],
Expand Down
2 changes: 1 addition & 1 deletion types/yauzl/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"module": "node16",
"lib": [
"es6"
"es2018"
],
"noImplicitAny": true,
"noImplicitThis": true,
Expand Down
36 changes: 36 additions & 0 deletions types/yauzl/yauzl-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,39 @@ if (fromDos.getTime() < 0) throw new Error("unreachable");
const decodedName: string = yauzl.getFileNameLowLevel(0x800, Buffer.from("a.txt"), [], true);
const parsed: yauzl.ExtraField[] = yauzl.parseExtraFields(Buffer.alloc(0));
if (decodedName.length < 0 || parsed.length < 0) throw new Error("unreachable");

// Promises API.
async function withPromises() {
const zipfile: yauzl.ZipFile = await yauzl.openPromise("path/to/file.zip");
await yauzl.openPromise("path/to/file.zip", { strictFileNames: true });
await yauzl.fromFdPromise(0);
await yauzl.fromBufferPromise(Buffer.alloc(0), { decodeStrings: false });
await yauzl.fromRandomAccessReaderPromise(new MemoryReader(), 1024);

for await (const entry of zipfile.eachEntry()) {
const name: string = entry.fileName;
if (name.length < 0) throw new Error("unreachable");

const readStream: Readable = await zipfile.openReadStreamPromise(entry);
readStream.pipe(new Writable());
await zipfile.openReadStreamPromise(entry, { decodeFileData: false });

const minimal = await zipfile.readLocalFileHeaderPromise(entry, { minimal: true });
const start: number = minimal.fileDataStart;

const header: yauzl.LocalFileHeader = await zipfile.readLocalFileHeaderPromise(entry);
const rawName: Buffer = header.fileName;
if (rawName.length < 0) throw new Error("unreachable");

const lowStream: Readable = await zipfile.openReadStreamLowLevelPromise(
start,
entry.compressedSize,
0,
entry.compressedSize,
true,
entry.uncompressedSize,
);
lowStream.pipe(new Writable());
}
}
withPromises();