From 494067f4ccc6d3fe93cf4d8b030ee2991af43a58 Mon Sep 17 00:00:00 2001 From: Ravi Luthra Date: Mon, 13 Nov 2017 12:59:27 -0700 Subject: [PATCH] New type definitions for npm package 'unzip' --- types/unzip/index.d.ts | 36 ++++++++++++++++++++++++++++++++++++ types/unzip/tsconfig.json | 23 +++++++++++++++++++++++ types/unzip/tslint.json | 1 + types/unzip/unzip-tests.ts | 18 ++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 types/unzip/index.d.ts create mode 100644 types/unzip/tsconfig.json create mode 100644 types/unzip/tslint.json create mode 100644 types/unzip/unzip-tests.ts diff --git a/types/unzip/index.d.ts b/types/unzip/index.d.ts new file mode 100644 index 0000000000..74dec93513 --- /dev/null +++ b/types/unzip/index.d.ts @@ -0,0 +1,36 @@ +// Type definitions for unzip 0.1 +// Project: https://github.com/EvanOxfeld/node-unzip +// Definitions by: Ravi L. +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + +export function Extract(options: { path: string }): NodeJS.WritableStream; +export function Parse(): NodeJS.WritableStream; + +/** + * Code example from https://www.npmjs.com/package/unzip with type unzip.Entry added + * ``` + * fs.createReadStream('path/to/archive.zip') + * .pipe(unzip.Parse()) + * .on('entry', function (entry: unzip.Entry) { + * var fileName = entry.path; + * var type = entry.type; // 'Directory' or 'File' + * var size = entry.size; + * if (fileName === "this IS the file I'm looking for") { + * entry.pipe(fs.createWriteStream('output/path')); + * } else { + * entry.autodrain(); + * } + * }); + * ``` + */ +export interface Entry { + path: string; + type: 'Directory' | 'File'; + size: number; + pipe: (stream: NodeJS.WritableStream) => void; + autodrain: () => void; +} + +/*~ You can declare properties of the module using const, let, or var */ +export const myField: number; diff --git a/types/unzip/tsconfig.json b/types/unzip/tsconfig.json new file mode 100644 index 0000000000..b5207a6cdc --- /dev/null +++ b/types/unzip/tsconfig.json @@ -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", + "unzip-tests.ts" + ] +} \ No newline at end of file diff --git a/types/unzip/tslint.json b/types/unzip/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/unzip/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/unzip/unzip-tests.ts b/types/unzip/unzip-tests.ts new file mode 100644 index 0000000000..c910af7722 --- /dev/null +++ b/types/unzip/unzip-tests.ts @@ -0,0 +1,18 @@ +import * as unzip from 'unzip'; +import * as fs from 'fs'; + +fs.createReadStream('path/to/archive.zip') + .pipe(unzip.Extract({ path: 'output/path' })); + +fs.createReadStream('path/to/archive.zip') + .pipe(unzip.Parse()) + .on('entry', (entry: unzip.Entry) => { + const fileName = entry.path; + const type = entry.type; // 'Directory' or 'File' + const size = entry.size; + if (fileName === "this IS the file I'm looking for") { + entry.pipe(fs.createWriteStream('output/path')); + } else { + entry.autodrain(); + } + });