diff --git a/node/node-tests.ts b/node/node-tests.ts index 3967c09c6a..32bdc94fdb 100644 --- a/node/node-tests.ts +++ b/node/node-tests.ts @@ -20,6 +20,7 @@ import * as cluster from "cluster"; import * as os from "os"; import * as vm from "vm"; import * as string_decoder from "string_decoder"; +import * as stream from "stream"; // Specifically test buffer module regression. import {Buffer as ImportedBuffer, SlowBuffer as ImportedSlowBuffer} from "buffer"; @@ -290,6 +291,70 @@ function stream_readable_pipe_test() { r.close(); } +// Simplified constructors +function simplified_stream_ctor_test() { + new stream.Readable({ + read: function (size) { + size.toFixed(); + } + }); + + new stream.Writable({ + write: function (chunk, enc, cb) { + chunk.slice(1); + enc.charAt(0); + cb() + }, + writev: function (chunks, cb) { + chunks[0].chunk.slice(0); + chunks[0].encoding.charAt(0); + cb(); + } + }); + + new stream.Duplex({ + read: function (size) { + size.toFixed(); + }, + write: function (chunk, enc, cb) { + chunk.slice(1); + enc.charAt(0); + cb() + }, + writev: function (chunks, cb) { + chunks[0].chunk.slice(0); + chunks[0].encoding.charAt(0); + cb(); + }, + readableObjectMode: true, + writableObjectMode: true + }); + + new stream.Transform({ + transform: function (chunk, enc, cb) { + chunk.slice(1); + enc.charAt(0); + cb(); + }, + flush: function (cb) { + cb() + }, + read: function (size) { + size.toFixed(); + }, + write: function (chunk, enc, cb) { + chunk.slice(1); + enc.charAt(0); + cb() + }, + writev: function (chunks, cb) { + chunks[0].chunk.slice(0); + chunks[0].encoding.charAt(0); + cb(); + } + }) +} + //////////////////////////////////////////////////// /// Crypto tests : http://nodejs.org/api/crypto.html //////////////////////////////////////////////////// diff --git a/node/node.d.ts b/node/node.d.ts index 9d08a014e8..bad534cdd7 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -2163,6 +2163,7 @@ declare module "stream" { highWaterMark?: number; encoding?: string; objectMode?: boolean; + read?: (size?: number) => any; } export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { @@ -2184,6 +2185,8 @@ 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 { @@ -2199,6 +2202,8 @@ declare module "stream" { export interface DuplexOptions extends ReadableOptions, WritableOptions { allowHalfOpen?: boolean; + readableObjectMode?: boolean; + writableObjectMode?: boolean; } // Note: Duplex extends both Readable and Writable. @@ -2213,7 +2218,10 @@ declare module "stream" { end(chunk: any, encoding?: string, cb?: Function): void; } - export interface TransformOptions extends ReadableOptions, WritableOptions { } + 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 {