mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-06 13:11:46 +00:00
Add simplified constructor syntax for node streams (#10105)
See https://nodejs.org/api/stream.html#stream_simplified_construction for API reference.
This commit is contained in:
committed by
Mohamed Hegazy
parent
005ea0faff
commit
91d45c49a3
@@ -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
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
Vendored
+9
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user