New type definitions for npm package 'unzip'

This commit is contained in:
Ravi Luthra
2017-11-13 12:59:27 -07:00
parent 642e90f456
commit 494067f4cc
4 changed files with 78 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
// Type definitions for unzip 0.1
// Project: https://github.com/EvanOxfeld/node-unzip
// Definitions by: Ravi L. <https://github.com/coding2012>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
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;
+23
View 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",
"unzip-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+18
View File
@@ -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();
}
});