Merge pull request #14484 from tlaziuk/pump

[pump] new definitions, v1.0
This commit is contained in:
Arthur Ozga
2017-02-09 13:16:07 -08:00
committed by GitHub
4 changed files with 91 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
// Type definitions for pump 1.0
// Project: https://github.com/mafintosh/pump
// Definitions by: Tomek Łaziuk <https://github.com/tlaziuk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
declare function pump(streams: pump.Stream[], callback?: pump.Callback): pump.Stream[];
// callback have to be passed as last argument
declare function pump(...streams: Array<pump.Stream | pump.Callback>): pump.Stream[];
declare namespace pump {
export type Callback = (err: Error) => any;
export type Stream = NodeJS.ReadableStream | NodeJS.WritableStream;
}
export = pump;
+52
View File
@@ -0,0 +1,52 @@
import * as pump from 'pump';
import { createReadStream, createWriteStream } from 'fs';
import { Transform } from 'stream';
const rs = createReadStream('/dev/random');
const ws = createWriteStream('/dev/null');
function toHex() {
const reverse: Transform = new Transform();
(reverse as any)._transform = (chunk: any, enc: any, callback: any) => {
reverse.push(chunk.toString('hex'));
callback();
};
return reverse;
}
let wsClosed = false;
let rsClosed = false;
let callbackCalled = false;
function check() {
if (wsClosed && rsClosed && callbackCalled) console.log(`pump finished`);
}
ws.on('close', () => {
wsClosed = true;
check();
});
rs.on('close', () => {
rsClosed = true;
check();
});
pump(rs, toHex(), toHex(), toHex(), ws, () => {
callbackCalled = true;
check();
});
setTimeout(() => {
rs.destroy();
}, 1000);
setTimeout(() => {
throw new Error('timeout');
}, 5000);
pump(createReadStream('/dev/random'), toHex(), createWriteStream('/dev/null'));
pump([createReadStream('/dev/random'), toHex(), createWriteStream('/dev/null')]);
+20
View File
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"pump-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "../tslint.json" }