mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 09:01:45 +08:00
Added support for unzipper npm package (#22858)
This commit is contained in:
committed by
Wesley Wigham
parent
ea29e9588e
commit
5cf07fc120
110
types/unzipper/index.d.ts
vendored
Normal file
110
types/unzipper/index.d.ts
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
// Type definitions for unzipper 0.8
|
||||
// Project: https://github.com/ZJONSSON/node-unzipper#readme
|
||||
// Definitions by: s73obrien <https://github.com/s73obrien>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Readable, Stream, PassThrough, Duplex } from "stream";
|
||||
import { ClientRequest, RequestOptions } from "http";
|
||||
|
||||
export interface PullStream extends Duplex {
|
||||
stream(eof: number | string, includeEof: boolean): PassThrough;
|
||||
pull(eof: number | string, includeEof: boolean): Promise<Buffer>;
|
||||
}
|
||||
|
||||
export interface Entry extends PassThrough {
|
||||
autodrain(): Promise<void>;
|
||||
buffer: Promise<Buffer>;
|
||||
path: string;
|
||||
|
||||
props: {
|
||||
path: string;
|
||||
};
|
||||
|
||||
type: string;
|
||||
vars: {
|
||||
signature?: number;
|
||||
versionsNeededToExtract: number;
|
||||
flags: number;
|
||||
compressionMethod: number;
|
||||
lastModifiedTime: number;
|
||||
crc32: number;
|
||||
compressedSize: number;
|
||||
fileNameLength: number;
|
||||
extraFieldLength: number;
|
||||
};
|
||||
|
||||
extra: {
|
||||
signature: number;
|
||||
partsize: number;
|
||||
uncompressedSize: number;
|
||||
compressedSize: number;
|
||||
offset: number;
|
||||
disknum: number;
|
||||
};
|
||||
}
|
||||
|
||||
export function unzip(
|
||||
source: {
|
||||
stream: Readable;
|
||||
size: Promise<number>
|
||||
},
|
||||
offset: number,
|
||||
_password: string): Entry;
|
||||
|
||||
export namespace Open {
|
||||
function file(filename: string): CentralDirectory;
|
||||
function url(request: ClientRequest, opt: string | RequestOptions): CentralDirectory;
|
||||
function s3(client: any, params: any): CentralDirectory;
|
||||
}
|
||||
|
||||
export function BufferStream(entry: Entry): Promise<Buffer>;
|
||||
|
||||
export interface CentralDirectory {
|
||||
signature: number;
|
||||
diskNumber: number;
|
||||
diskStart: number;
|
||||
numberOfRecordsOnDisk: number;
|
||||
numberOfRecords: number;
|
||||
sizeOfCentralDirectory: number;
|
||||
offsetToStartOfCentralDirectory: number;
|
||||
commentLength: number;
|
||||
files: [
|
||||
{
|
||||
signature: number;
|
||||
versionMadeBy: number;
|
||||
versionsNeededToExtract: number;
|
||||
flags: number;
|
||||
compressionMethod: number;
|
||||
lastModifiedTime: number;
|
||||
lastModifiedDate: number;
|
||||
crc32: number;
|
||||
compressedSize: number;
|
||||
uncompressedSize: number;
|
||||
fileNameLength: number;
|
||||
extraFieldLength: number;
|
||||
fileCommentLength: number;
|
||||
diskNumber: number;
|
||||
internalFileAttributes: number;
|
||||
externalFileAttributes: number;
|
||||
offsetToLocalFileHeader: number;
|
||||
path: string;
|
||||
comment: string;
|
||||
stream: Entry;
|
||||
buffer: Promise<Buffer>;
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
export class ParseOptions {
|
||||
verbose: boolean;
|
||||
// more options?
|
||||
}
|
||||
|
||||
export type ParseStream = PullStream & {
|
||||
promise: Promise<void>
|
||||
};
|
||||
|
||||
export function Parse(opts?: ParseOptions): ParseStream;
|
||||
export function ParseOne(match: RegExp, opts: ParseOptions): Duplex;
|
||||
export function Extract(opts?: ParseOptions): ParseStream;
|
||||
23
types/unzipper/tsconfig.json
Normal file
23
types/unzipper/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",
|
||||
"unzipper-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/unzipper/tslint.json
Normal file
1
types/unzipper/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
44
types/unzipper/unzipper-tests.ts
Normal file
44
types/unzipper/unzipper-tests.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
Parse,
|
||||
Open,
|
||||
Entry,
|
||||
CentralDirectory
|
||||
} from 'unzipper';
|
||||
|
||||
import { createReadStream } from 'fs';
|
||||
|
||||
import { get } from 'http';
|
||||
|
||||
createReadStream(
|
||||
'http://example.org/path/to/archive.zip'
|
||||
).pipe(
|
||||
Parse()
|
||||
).on('entry', (entry: Entry) => {
|
||||
entry.buffer.then((b1: Buffer) => {});
|
||||
const s1: string = entry.path;
|
||||
const s2: string = entry.type;
|
||||
const o1: {
|
||||
signature?: number;
|
||||
versionsNeededToExtract: number;
|
||||
flags: number;
|
||||
compressionMethod: number;
|
||||
lastModifiedTime: number;
|
||||
crc32: number;
|
||||
compressedSize: number;
|
||||
fileNameLength: number;
|
||||
extraFieldLength: number;
|
||||
} = entry.vars;
|
||||
|
||||
const o2: {
|
||||
signature: number;
|
||||
partsize: number;
|
||||
uncompressedSize: number;
|
||||
compressedSize: number;
|
||||
offset: number;
|
||||
disknum: number;
|
||||
} = entry.extra;
|
||||
});
|
||||
|
||||
const dir1: CentralDirectory = Open.file('Z:\\path\\to\\archive.zip');
|
||||
const dir2: CentralDirectory = Open.url(get('url/to/archive.zip'), {});
|
||||
const dir3: CentralDirectory = Open.s3('any', 'any');
|
||||
Reference in New Issue
Block a user