Skip to content

Commit

Permalink
Node.d.ts: Update definitions for module "stream" (DefinitelyTyped#11086
Browse files Browse the repository at this point in the history
)

* Node.d.ts: Update definitions for module "stream"

* Node.d.ts: Fix an issue that caused tests to fail
  • Loading branch information
hriss95 authored and vvakame committed Sep 9, 2016
1 parent aee853c commit ab57464
Showing 1 changed file with 90 additions and 84 deletions.
174 changes: 90 additions & 84 deletions node/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2399,102 +2399,108 @@ declare module "crypto" {
declare module "stream" {
import * as events from "events";

export class Stream extends events.EventEmitter {
class internal extends events.EventEmitter {
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
}
namespace internal {

export interface ReadableOptions {
highWaterMark?: number;
encoding?: string;
objectMode?: boolean;
read?: (size?: number) => any;
}
export class Stream extends internal {}

export class Readable extends events.EventEmitter implements NodeJS.ReadableStream {
readable: boolean;
constructor(opts?: ReadableOptions);
_read(size: number): void;
read(size?: number): any;
setEncoding(encoding: string): void;
pause(): Readable;
resume(): Readable;
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;
}
export interface ReadableOptions {
highWaterMark?: number;
encoding?: string;
objectMode?: boolean;
read?: (size?: number) => any;
}

export interface WritableOptions {
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 Readable extends events.EventEmitter implements NodeJS.ReadableStream {
readable: boolean;
constructor(opts?: ReadableOptions);
_read(size: number): void;
read(size?: number): any;
setEncoding(encoding: string): void;
pause(): Readable;
resume(): Readable;
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;
}

export class Writable extends events.EventEmitter implements NodeJS.WritableStream {
writable: boolean;
constructor(opts?: WritableOptions);
_write(chunk: any, encoding: string, callback: Function): void;
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;
}
export interface WritableOptions {
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 interface DuplexOptions extends ReadableOptions, WritableOptions {
allowHalfOpen?: boolean;
readableObjectMode?: boolean;
writableObjectMode?: boolean;
}
export class Writable extends events.EventEmitter implements NodeJS.WritableStream {
writable: boolean;
constructor(opts?: WritableOptions);
_write(chunk: any, encoding: string, callback: Function): void;
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;
}

// Note: Duplex extends both Readable and Writable.
export class Duplex extends Readable implements NodeJS.ReadWriteStream {
// Readable
pause(): Duplex;
resume(): Duplex;
// Writeable
writable: boolean;
constructor(opts?: DuplexOptions);
_write(chunk: any, encoding: string, callback: Function): void;
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;
}
export interface DuplexOptions extends ReadableOptions, WritableOptions {
allowHalfOpen?: boolean;
readableObjectMode?: boolean;
writableObjectMode?: boolean;
}

export interface TransformOptions extends ReadableOptions, WritableOptions {
transform?: (chunk: string|Buffer, encoding: string, callback: Function) => any;
flush?: (callback: Function) => any;
}
// Note: Duplex extends both Readable and Writable.
export class Duplex extends Readable implements NodeJS.ReadWriteStream {
// Readable
pause(): Duplex;
resume(): Duplex;
// Writeable
writable: boolean;
constructor(opts?: DuplexOptions);
_write(chunk: any, encoding: string, callback: Function): void;
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;
}

// Note: Transform lacks the _read and _write methods of Readable/Writable.
export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream {
readable: boolean;
writable: boolean;
constructor(opts?: TransformOptions);
_transform(chunk: any, encoding: string, callback: Function): void;
_flush(callback: Function): void;
read(size?: number): any;
setEncoding(encoding: string): void;
pause(): Transform;
resume(): Transform;
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;
export interface TransformOptions extends ReadableOptions, WritableOptions {
transform?: (chunk: string|Buffer, encoding: string, callback: Function) => any;
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;
constructor(opts?: TransformOptions);
_transform(chunk: any, encoding: string, callback: Function): void;
_flush(callback: Function): void;
read(size?: number): any;
setEncoding(encoding: string): void;
pause(): Transform;
resume(): Transform;
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;
}

export class PassThrough extends Transform { }
}

export class PassThrough extends Transform { }
export = internal;
}

declare module "util" {
Expand Down

0 comments on commit ab57464

Please sign in to comment.