From c2fac6d23595aebaae11bbb4e45b598ceae29bd0 Mon Sep 17 00:00:00 2001 From: Kon Pik <485881+konpikwastaken@users.noreply.github.com> Date: Thu, 22 Nov 2018 09:14:42 -0800 Subject: [PATCH] Updating definitions for combined-stream v1.0.7 (#30295) * updates * PR feedback * updated PR changes --- .../combined-stream/combined-stream-tests.ts | 35 +++++++++++----- types/combined-stream/index.d.ts | 40 +++++++++---------- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/types/combined-stream/combined-stream-tests.ts b/types/combined-stream/combined-stream-tests.ts index ffdc0eaac7..540db77b68 100644 --- a/types/combined-stream/combined-stream-tests.ts +++ b/types/combined-stream/combined-stream-tests.ts @@ -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; +}; diff --git a/types/combined-stream/index.d.ts b/types/combined-stream/index.d.ts index 271814a4af..b82b399e7f 100644 --- a/types/combined-stream/index.d.ts +++ b/types/combined-stream/index.d.ts @@ -1,19 +1,27 @@ // Type definitions for combined-stream 1.0 // Project: https://github.com/felixge/node-combined-stream -// Definitions by: Felix Geisendörfer , Tomek Łaziuk +// Definitions by: Felix Geisendörfer , Tomek Łaziuk , Kon Pik // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// -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;