mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-01 03:20:46 +08:00
Merge pull request #26212 from dlee-nvisia/master
Add typings for yauzl-promise
This commit is contained in:
68
types/yauzl-promise/index.d.ts
vendored
Normal file
68
types/yauzl-promise/index.d.ts
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
// Type definitions for yauzl-promise 2.1
|
||||
// Project: https://github.com/overlookmotel/yauzl-promise
|
||||
// Definitions by: Dave Lee <https://github.com/dlee-nvisia>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Entry as BaseEntry, Options, ZipFileOptions, RandomAccessReader } from 'yauzl';
|
||||
import { Readable } from 'stream';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
// This class is not directly compatible with @types/yauzl 's ZipFile as this library changes the function signatures
|
||||
// Therefore, it is replaced, albeit with a significant portion
|
||||
export class ZipFile extends EventEmitter {
|
||||
// This chunk taken directly from @types/yauzl
|
||||
autoClose: boolean;
|
||||
comment: string;
|
||||
decodeStrings: boolean;
|
||||
emittedError: boolean;
|
||||
entriesRead: number;
|
||||
entryCount: number;
|
||||
fileSize: number;
|
||||
isOpen: boolean;
|
||||
lazyEntries: boolean;
|
||||
readEntryCursor: boolean;
|
||||
validateEntrySizes: boolean;
|
||||
|
||||
constructor(
|
||||
reader: RandomAccessReader,
|
||||
centralDirectoryOffset: number,
|
||||
fileSize: number,
|
||||
entryCount: number,
|
||||
comment: string,
|
||||
autoClose: boolean,
|
||||
lazyEntries: boolean,
|
||||
decodeStrings: boolean,
|
||||
validateEntrySizes: boolean,
|
||||
);
|
||||
|
||||
// These funcitons are custom to yauzl-promise
|
||||
|
||||
close(): Promise<void>;
|
||||
readEntry(): Promise<Entry>;
|
||||
readEntries(numEntries?: number): Promise<Entry[]>;
|
||||
walkEntries(callback: (entry: Entry) => Promise<void> | void, numEntries?: number): Promise<void>;
|
||||
openReadStream(entry: Entry, options?: ZipFileOptions): Promise<Readable>;
|
||||
}
|
||||
|
||||
export class Entry extends BaseEntry {
|
||||
openReadStream(options?: ZipFileOptions): Promise<Readable>;
|
||||
}
|
||||
|
||||
export function open(path: string, options?: Options): Promise<ZipFile>;
|
||||
// export function open(path: string): Promise<ZipFile>;
|
||||
export function fromFd(fd: number, options?: Options): Promise<ZipFile>;
|
||||
// export function fromFd(fd: number): Promise<ZipFile>;
|
||||
export function fromBuffer(buffer: Buffer, options?: Options): Promise<ZipFile>;
|
||||
// export function fromBuffer(buffer: Buffer): Promise<ZipFile>;
|
||||
export function fromRandomAccessReader(reader: RandomAccessReader, totalSize: number, options?: Options): Promise<ZipFile>;
|
||||
// export function fromRandomAccessReader(reader: RandomAccessReader, totalSize: number): Promise<ZipFile>;
|
||||
|
||||
// These are copied directly from @types/yauzl, I beleive they are unmodified
|
||||
export function dosDateTimeToDate(date: number, time: number): Date;
|
||||
export function validateFileName(fileName: string): string | null;
|
||||
|
||||
export { RandomAccessReader, Options, ZipFileOptions };
|
||||
23
types/yauzl-promise/tsconfig.json
Normal file
23
types/yauzl-promise/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"yauzl-promise-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/yauzl-promise/tslint.json
Normal file
1
types/yauzl-promise/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
49
types/yauzl-promise/yauzl-promise-tests.ts
Normal file
49
types/yauzl-promise/yauzl-promise-tests.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import * as yauzl from 'yauzl-promise';
|
||||
|
||||
class FakeRaR extends yauzl.RandomAccessReader {}
|
||||
|
||||
const options: yauzl.Options = {
|
||||
autoClose: true
|
||||
};
|
||||
|
||||
const zipOptions: yauzl.ZipFileOptions = {
|
||||
decrypt: true,
|
||||
decompress: true,
|
||||
start: 0,
|
||||
end: 1
|
||||
};
|
||||
|
||||
const date = yauzl.dosDateTimeToDate(1, 1);
|
||||
const fn = yauzl.validateFileName("fake");
|
||||
|
||||
async function test() {
|
||||
const zip = await yauzl.open("");
|
||||
const open2 = await yauzl.open("", options);
|
||||
|
||||
const fd1 = await yauzl.fromFd(0);
|
||||
const fd2 = await yauzl.fromFd(0, options);
|
||||
|
||||
const buffer1 = await yauzl.fromBuffer(Buffer.from("test", "utf-8"));
|
||||
const buffer2 = await yauzl.fromBuffer(Buffer.from("test", "utf-8"), options);
|
||||
|
||||
const rar1 = await yauzl.fromRandomAccessReader(new FakeRaR(), 1);
|
||||
const rar2 = await yauzl.fromRandomAccessReader(new FakeRaR(), 1, options);
|
||||
|
||||
const entry = await zip.readEntry();
|
||||
await zip.readEntries();
|
||||
await zip.readEntries(1);
|
||||
|
||||
const rs = await zip.openReadStream(entry);
|
||||
await zip.openReadStream(entry, zipOptions);
|
||||
|
||||
await entry.openReadStream();
|
||||
await entry.openReadStream(zipOptions);
|
||||
|
||||
await zip.walkEntries(async (entry: yauzl.Entry) => {
|
||||
console.log("foo");
|
||||
});
|
||||
|
||||
await zip.walkEntries(async (entry: yauzl.Entry) => {
|
||||
console.log("foo");
|
||||
}, 1);
|
||||
}
|
||||
Reference in New Issue
Block a user