Updating definitions for combined-stream v1.0.7 (#30295)

* updates

* PR feedback

* updated PR changes
This commit is contained in:
Kon Pik 2018-11-22 09:14:42 -08:00 committed by Pranav Senthilnathan
parent 28be0fcccb
commit c2fac6d235
2 changed files with 46 additions and 29 deletions

View File

@ -1,17 +1,17 @@
import CombinedStream = require("combined-stream");
import { createReadStream, createWriteStream } from "fs";
import CombinedStream = require('combined-stream');
import { createReadStream, createWriteStream } from 'fs';
const stream1 = new CombinedStream();
stream1.append(createReadStream("tsconfig.json"));
stream1.append(createReadStream("tslint.json"));
stream1.append(createReadStream("index.d.ts"));
stream1.append(createReadStream('tsconfig.json'));
stream1.append(createReadStream('tslint.json'));
stream1.append(createReadStream('index.d.ts'));
stream1.pipe(createWriteStream("combined.txt"));
stream1.pipe(createWriteStream('combined.txt'));
const stream2 = CombinedStream.create({
maxDataSize: 1 << 32,
pauseStreams: false,
pauseStreams: false
});
stream1.destroy();
@ -19,12 +19,29 @@ stream1.destroy();
// should log true
console.log(CombinedStream.isStreamLike(stream2));
stream2.on("data", (data) => {
stream2.on('data', data => {
console.log(data);
});
stream2.pipe(createWriteStream("combined.txt"));
stream2.pipe(createWriteStream('combined.txt'));
stream2.write(CombinedStream.name);
stream2.destroy();
const arrowFunction = (): CombinedStream => {
const stream3 = new CombinedStream();
// test next function
stream3.append(next => {
stream3.append('hello world');
next(createReadStream(''));
});
// next function with no next
stream3.append(() => {
stream3.append('hello again');
});
return stream3;
};

View File

@ -1,19 +1,27 @@
// Type definitions for combined-stream 1.0
// Project: https://github.com/felixge/node-combined-stream
// Definitions by: Felix Geisendörfer <https://github.com/felixge>, Tomek Łaziuk <https://github.com/tlaziuk>
// Definitions by: Felix Geisendörfer <https://github.com/felixge>, Tomek Łaziuk <https://github.com/tlaziuk>, Kon Pik <https://github.com/konpikwastaken>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { Stream } from "stream";
import { Stream } from 'stream';
declare class CombinedStream extends Stream implements CombinedStream.Options {
type Appendable = NodeJS.ReadableStream | NodeJS.WritableStream | Buffer | string | NextFunction;
type NextFunction = (next: (stream: Appendable) => any) => any;
interface Options {
maxDataSize?: number;
pauseStreams?: boolean;
}
declare class CombinedStream extends Stream implements Options {
readonly writable: boolean;
readonly readable: boolean;
readonly dataSize: number;
maxDataSize: number;
pauseStreams: boolean;
append(stream: NodeJS.ReadableStream | NodeJS.WritableStream | Buffer | string): this;
append(stream: Appendable): this;
write(data: any): void;
pause(): void;
resume(): void;
@ -34,23 +42,15 @@ declare class CombinedStream extends Stream implements CombinedStream.Options {
_emitError(error: Error): void;
// events
on(event: "close" | "end" | "resume" | "pause", cb: () => void): this;
on(event: "error", cb: (err: Error) => void): this;
on(event: "data", cb: (data: any) => void): this;
once(event: "close" | "end" | "resume" | "pause", cb: () => void): this;
once(event: "error", cb: (err: Error) => void): this;
once(event: "data", cb: (data: any) => void): this;
}
on(event: 'close' | 'end' | 'resume' | 'pause', cb: () => void): this;
on(event: 'error', cb: (err: Error) => void): this;
on(event: 'data', cb: (data: any) => void): this;
once(event: 'close' | 'end' | 'resume' | 'pause', cb: () => void): this;
once(event: 'error', cb: (err: Error) => void): this;
once(event: 'data', cb: (data: any) => void): this;
declare namespace CombinedStream {
interface Options {
maxDataSize?: number;
pauseStreams?: boolean;
}
function create(options?: Options): CombinedStream;
function isStreamLike(stream: any): stream is Stream;
static create(options?: Options): CombinedStream;
static isStreamLike(stream: any): stream is Stream;
}
export = CombinedStream;