mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
Merge pull request #14484 from tlaziuk/pump
[pump] new definitions, v1.0
This commit is contained in:
Vendored
+18
@@ -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;
|
||||
@@ -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')]);
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user