Merge pull request #15831 from blakeembrey/node-streams

[node] Update and correct node.js stream interfaces
This commit is contained in:
Ryan Cavanaugh
2017-04-17 14:26:28 -07:00
committed by GitHub
4 changed files with 82 additions and 142 deletions

58
types/node/index.d.ts vendored
View File

@@ -290,7 +290,6 @@ declare namespace NodeJS {
export interface ReadableStream extends EventEmitter {
readable: boolean;
isTTY?: boolean;
read(size?: number): string | Buffer;
setEncoding(encoding: string | null): this;
pause(): this;
@@ -305,7 +304,6 @@ declare namespace NodeJS {
export interface WritableStream extends EventEmitter {
writable: boolean;
isTTY?: boolean;
write(buffer: Buffer | string, cb?: Function): boolean;
write(str: string, encoding?: string, cb?: Function): boolean;
end(): void;
@@ -364,10 +362,14 @@ declare namespace NodeJS {
| 'sunos'
| 'win32';
export interface Socket extends ReadWriteStream {
isTTY?: true;
}
export interface Process extends EventEmitter {
stdout: WritableStream;
stderr: WritableStream;
stdin: ReadableStream;
stdout: Socket;
stderr: Socket;
stdin: Socket;
argv: string[];
argv0: string;
execArgv: string[];
@@ -3424,6 +3426,7 @@ declare module "stream" {
class internal extends events.EventEmitter {
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
}
namespace internal {
export class Stream extends internal { }
@@ -3432,13 +3435,13 @@ declare module "stream" {
highWaterMark?: number;
encoding?: string;
objectMode?: boolean;
read?: (size?: number) => any;
read?: (this: Readable, size?: number) => any;
}
export class Readable extends events.EventEmitter implements NodeJS.ReadableStream {
export class Readable extends Stream implements NodeJS.ReadableStream {
readable: boolean;
constructor(opts?: ReadableOptions);
protected _read(size: number): void;
_read(size: number): void;
read(size?: number): any;
setEncoding(encoding: string): this;
pause(): this;
@@ -3447,7 +3450,7 @@ declare module "stream" {
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
unpipe<T extends NodeJS.WritableStream>(destination?: T): this;
unshift(chunk: any): void;
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
wrap(oldStream: NodeJS.ReadableStream): Readable;
push(chunk: any, encoding?: string): boolean;
/**
@@ -3518,12 +3521,13 @@ declare module "stream" {
writev?: (chunks: { chunk: string | Buffer, encoding: string }[], callback: Function) => any;
}
export class Writable extends events.EventEmitter implements NodeJS.WritableStream {
export class Writable extends Stream implements NodeJS.WritableStream {
writable: boolean;
constructor(opts?: WritableOptions);
protected _write(chunk: any, encoding: string, callback: Function): void;
_write(chunk: any, encoding: string, callback: Function): void;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
setDefaultEncoding(encoding: string): this;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
@@ -3602,16 +3606,13 @@ declare module "stream" {
}
// Note: Duplex extends both Readable and Writable.
export class Duplex extends Readable implements NodeJS.ReadWriteStream {
// Readable
pause(): this;
resume(): this;
// Writeable
export class Duplex extends Readable implements Writable {
writable: boolean;
constructor(opts?: DuplexOptions);
protected _write(chunk: any, encoding: string, callback: Function): void;
_write(chunk: any, encoding: string, callback: Function): void;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
setDefaultEncoding(encoding: string): this;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
@@ -3622,28 +3623,9 @@ declare module "stream" {
flush?: (callback: Function) => any;
}
// Note: Transform lacks the _read and _write methods of Readable/Writable.
export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream {
readable: boolean;
writable: boolean;
export class Transform extends Duplex {
constructor(opts?: TransformOptions);
protected _transform(chunk: any, encoding: string, callback: Function): void;
protected _flush(callback: Function): void;
read(size?: number): any;
setEncoding(encoding: string): this;
pause(): this;
resume(): this;
isPaused(): boolean;
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
unpipe<T extends NodeJS.WritableStream>(destination?: T): this;
unshift(chunk: any): void;
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
push(chunk: any, encoding?: string): boolean;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
_transform(chunk: any, encoding: string, callback: Function): void;
}
export class PassThrough extends Transform { }

View File

@@ -180,7 +180,6 @@ declare namespace NodeJS {
export interface ReadableStream extends EventEmitter {
readable: boolean;
isTTY?: boolean;
read(size?: number): string|Buffer;
setEncoding(encoding: string): void;
pause(): void;
@@ -195,7 +194,6 @@ declare namespace NodeJS {
export interface WritableStream extends EventEmitter {
writable: boolean;
isTTY?: boolean;
write(buffer: Buffer|string, cb?: Function): boolean;
write(str: string, encoding?: string, cb?: Function): boolean;
end(): void;
@@ -206,10 +204,14 @@ declare namespace NodeJS {
export interface ReadWriteStream extends ReadableStream, WritableStream {}
export interface Socket extends ReadWriteStream {
isTTY?: true;
}
export interface Process extends EventEmitter {
stdout: WritableStream;
stderr: WritableStream;
stdin: ReadableStream;
stdout: Socket;
stderr: Socket;
stdin: Socket;
argv: string[];
execPath: string;
abort(): void;
@@ -1716,7 +1718,7 @@ declare module "crypto" {
declare module "stream" {
import * as events from "events";
export interface Stream extends events.EventEmitter {
export class Stream extends events.EventEmitter {
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
}
@@ -1726,10 +1728,10 @@ declare module "stream" {
objectMode?: boolean;
}
export class Readable extends events.EventEmitter implements NodeJS.ReadableStream {
export class Readable extends Stream implements NodeJS.ReadableStream {
readable: boolean;
constructor(opts?: ReadableOptions);
protected _read(size: number): void;
_read(size: number): void;
read(size?: number): any;
setEncoding(encoding: string): void;
pause(): void;
@@ -1738,7 +1740,7 @@ declare module "stream" {
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
unpipe<T extends NodeJS.WritableStream>(destination?: T): void;
unshift(chunk: any): void;
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
wrap(oldStream: NodeJS.ReadableStream): Readable;
push(chunk: any, encoding?: string): boolean;
}
@@ -1748,12 +1750,13 @@ declare module "stream" {
objectMode?: boolean;
}
export class Writable extends events.EventEmitter implements NodeJS.WritableStream {
export class Writable extends Stream implements NodeJS.WritableStream {
writable: boolean;
constructor(opts?: WritableOptions);
protected _write(chunk: any, encoding: string, callback: Function): void;
_write(chunk: any, encoding: string, callback: Function): void;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
setDefaultEncoding(encoding: string): this;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
@@ -1764,12 +1767,13 @@ declare module "stream" {
}
// Note: Duplex extends both Readable and Writable.
export class Duplex extends Readable implements NodeJS.ReadWriteStream {
export class Duplex extends Readable implements Writable {
writable: boolean;
constructor(opts?: DuplexOptions);
protected _write(chunk: any, encoding: string, callback: Function): void;
_write(chunk: any, encoding: string, callback: Function): void;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
setDefaultEncoding(encoding: string): this;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
@@ -1778,27 +1782,9 @@ declare module "stream" {
export interface TransformOptions extends ReadableOptions, WritableOptions {}
// Note: Transform lacks the _read and _write methods of Readable/Writable.
export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream {
readable: boolean;
writable: boolean;
export class Transform extends Duplex implements NodeJS.ReadWriteStream {
constructor(opts?: TransformOptions);
protected _transform(chunk: any, encoding: string, callback: Function): void;
protected _flush(callback: Function): void;
read(size?: number): any;
setEncoding(encoding: string): void;
pause(): void;
resume(): void;
isPaused(): boolean;
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
unpipe<T extends NodeJS.WritableStream>(destination?: T): void;
unshift(chunk: any): void;
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
push(chunk: any, encoding?: string): boolean;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
_transform(chunk: any, encoding: string, callback: Function): void;
}
export class PassThrough extends Transform {}

View File

@@ -251,7 +251,6 @@ declare namespace NodeJS {
export interface ReadableStream extends EventEmitter {
readable: boolean;
isTTY?: boolean;
read(size?: number): string|Buffer;
setEncoding(encoding: string): void;
pause(): void;
@@ -266,7 +265,6 @@ declare namespace NodeJS {
export interface WritableStream extends EventEmitter {
writable: boolean;
isTTY?: boolean;
write(buffer: Buffer|string, cb?: Function): boolean;
write(str: string, encoding?: string, cb?: Function): boolean;
end(): void;
@@ -300,10 +298,14 @@ declare namespace NodeJS {
heapUsed: number;
}
export interface Socket extends ReadWriteStream {
isTTY?: true;
}
export interface Process extends EventEmitter {
stdout: WritableStream;
stderr: WritableStream;
stdin: ReadableStream;
stdout: Socket;
stderr: Socket;
stdin: Socket;
argv: string[];
execArgv: string[];
execPath: string;
@@ -2067,12 +2069,13 @@ declare module "stream" {
highWaterMark?: number;
encoding?: string;
objectMode?: boolean;
read?: (this: Readable, size?: number) => any;
}
export class Readable extends events.EventEmitter implements NodeJS.ReadableStream {
export class Readable extends Stream implements NodeJS.ReadableStream {
readable: boolean;
constructor(opts?: ReadableOptions);
protected _read(size: number): void;
_read(size: number): void;
read(size?: number): any;
setEncoding(encoding: string): void;
pause(): void;
@@ -2081,7 +2084,7 @@ declare module "stream" {
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
unpipe<T extends NodeJS.WritableStream>(destination?: T): void;
unshift(chunk: any): void;
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
wrap(oldStream: NodeJS.ReadableStream): Readable;
push(chunk: any, encoding?: string): boolean;
}
@@ -2089,14 +2092,17 @@ declare module "stream" {
highWaterMark?: number;
decodeStrings?: boolean;
objectMode?: boolean;
write?: (chunk: string | Buffer, encoding: string, callback: Function) => any;
writev?: (chunks: { chunk: string | Buffer, encoding: string }[], callback: Function) => any;
}
export class Writable extends events.EventEmitter implements NodeJS.WritableStream {
export class Writable extends Stream implements NodeJS.WritableStream {
writable: boolean;
constructor(opts?: WritableOptions);
protected _write(chunk: any, encoding: string, callback: Function): void;
_write(chunk: any, encoding: string, callback: Function): void;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
setDefaultEncoding(encoding: string): this;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
@@ -2104,15 +2110,18 @@ declare module "stream" {
export interface DuplexOptions extends ReadableOptions, WritableOptions {
allowHalfOpen?: boolean;
readableObjectMode?: boolean;
writableObjectMode?: boolean;
}
// Note: Duplex extends both Readable and Writable.
export class Duplex extends Readable implements NodeJS.ReadWriteStream {
export class Duplex extends Readable implements Writable {
writable: boolean;
constructor(opts?: DuplexOptions);
protected _write(chunk: any, encoding: string, callback: Function): void;
_write(chunk: any, encoding: string, callback: Function): void;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
setDefaultEncoding(encoding: string): this;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
@@ -2120,28 +2129,9 @@ declare module "stream" {
export interface TransformOptions extends ReadableOptions, WritableOptions {}
// Note: Transform lacks the _read and _write methods of Readable/Writable.
export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream {
readable: boolean;
writable: boolean;
export class Transform extends Duplex {
constructor(opts?: TransformOptions);
protected _transform(chunk: any, encoding: string, callback: Function): void;
protected _flush(callback: Function): void;
read(size?: number): any;
setEncoding(encoding: string): void;
pause(): void;
resume(): void;
isPaused(): boolean;
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
unpipe<T extends NodeJS.WritableStream>(destination?: T): void;
unshift(chunk: any): void;
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
push(chunk: any, encoding?: string): boolean;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
_transform(chunk: any, encoding: string, callback: Function): void;
}
export class PassThrough extends Transform {}

View File

@@ -279,7 +279,6 @@ declare namespace NodeJS {
export interface ReadableStream extends EventEmitter {
readable: boolean;
isTTY?: boolean;
read(size?: number): string | Buffer;
setEncoding(encoding: string | null): void;
pause(): ReadableStream;
@@ -294,7 +293,6 @@ declare namespace NodeJS {
export interface WritableStream extends EventEmitter {
writable: boolean;
isTTY?: boolean;
write(buffer: Buffer | string, cb?: Function): boolean;
write(str: string, encoding?: string, cb?: Function): boolean;
end(): void;
@@ -356,10 +354,14 @@ declare namespace NodeJS {
| 'sunos'
| 'win32';
export interface Socket extends ReadWriteStream {
isTTY?: true;
}
export interface Process extends EventEmitter {
stdout: WritableStream;
stderr: WritableStream;
stdin: ReadableStream;
stdout: Socket;
stderr: Socket;
stdin: Socket;
argv: string[];
argv0: string;
execArgv: string[];
@@ -3335,6 +3337,7 @@ declare module "stream" {
class internal extends events.EventEmitter {
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
}
namespace internal {
export class Stream extends internal { }
@@ -3343,13 +3346,13 @@ declare module "stream" {
highWaterMark?: number;
encoding?: string;
objectMode?: boolean;
read?: (size?: number) => any;
read?: (this: Readable, size?: number) => any;
}
export class Readable extends events.EventEmitter implements NodeJS.ReadableStream {
export class Readable extends Stream implements NodeJS.ReadableStream {
readable: boolean;
constructor(opts?: ReadableOptions);
protected _read(size: number): void;
_read(size: number): void;
read(size?: number): any;
setEncoding(encoding: string): void;
pause(): Readable;
@@ -3358,7 +3361,7 @@ declare module "stream" {
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
unpipe<T extends NodeJS.WritableStream>(destination?: T): void;
unshift(chunk: any): void;
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
wrap(oldStream: NodeJS.ReadableStream): Readable;
push(chunk: any, encoding?: string): boolean;
/**
@@ -3429,12 +3432,13 @@ declare module "stream" {
writev?: (chunks: { chunk: string | Buffer, encoding: string }[], callback: Function) => any;
}
export class Writable extends events.EventEmitter implements NodeJS.WritableStream {
export class Writable extends Stream implements NodeJS.WritableStream {
writable: boolean;
constructor(opts?: WritableOptions);
protected _write(chunk: any, encoding: string, callback: Function): void;
_write(chunk: any, encoding: string, callback: Function): void;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
setDefaultEncoding(encoding: string): this;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
@@ -3513,16 +3517,13 @@ declare module "stream" {
}
// Note: Duplex extends both Readable and Writable.
export class Duplex extends Readable implements NodeJS.ReadWriteStream {
// Readable
pause(): Duplex;
resume(): Duplex;
// Writeable
export class Duplex extends Readable implements Writable {
writable: boolean;
constructor(opts?: DuplexOptions);
protected _write(chunk: any, encoding: string, callback: Function): void;
_write(chunk: any, encoding: string, callback: Function): void;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
setDefaultEncoding(encoding: string): this;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
@@ -3533,28 +3534,9 @@ declare module "stream" {
flush?: (callback: Function) => any;
}
// Note: Transform lacks the _read and _write methods of Readable/Writable.
export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream {
readable: boolean;
writable: boolean;
export class Transform extends Duplex {
constructor(opts?: TransformOptions);
protected _transform(chunk: any, encoding: string, callback: Function): void;
protected _flush(callback: Function): void;
read(size?: number): any;
setEncoding(encoding: string): void;
pause(): Transform;
resume(): Transform;
isPaused(): boolean;
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
unpipe<T extends NodeJS.WritableStream>(destination?: T): void;
unshift(chunk: any): void;
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
push(chunk: any, encoding?: string): boolean;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
_transform(chunk: any, encoding: string, callback: Function): void;
}
export class PassThrough extends Transform { }