fix(node): backport stream.finished options since v10 (#43959)

This commit is contained in:
Jonathan Stewmon
2020-04-17 14:08:58 -07:00
committed by GitHub
parent 652078fa60
commit 9f76d795b2
5 changed files with 31 additions and 5 deletions
+7 -1
View File
@@ -244,9 +244,15 @@ declare module "stream" {
class PassThrough extends Transform { }
interface FinishedOptions {
error?: boolean;
readable?: boolean;
writable?: boolean;
}
function finished(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, options: FinishedOptions, callback: (err?: NodeJS.ErrnoException | null) => void): () => void;
function finished(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, callback: (err?: NodeJS.ErrnoException | null) => void): () => void;
namespace finished {
function __promisify__(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream): Promise<void>;
function __promisify__(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, options?: FinishedOptions): Promise<void>;
}
function pipeline<T extends NodeJS.WritableStream>(stream1: NodeJS.ReadableStream, stream2: T, callback?: (err: NodeJS.ErrnoException | null) => void): T;
+7 -1
View File
@@ -246,9 +246,15 @@ declare module "stream" {
class PassThrough extends Transform { }
interface FinishedOptions {
error?: boolean;
readable?: boolean;
writable?: boolean;
}
function finished(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, options: FinishedOptions, callback: (err?: NodeJS.ErrnoException | null) => void): () => void;
function finished(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, callback: (err?: NodeJS.ErrnoException | null) => void): () => void;
namespace finished {
function __promisify__(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream): Promise<void>;
function __promisify__(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, options?: FinishedOptions): Promise<void>;
}
function pipeline<T extends NodeJS.WritableStream>(stream1: NodeJS.ReadableStream, stream2: T, callback?: (err: NodeJS.ErrnoException | null) => void): T;
+5 -1
View File
@@ -159,7 +159,10 @@ function simplified_stream_ctor_test() {
}
function streamPipelineFinished() {
const cancel = finished(process.stdin, (err?: Error | null) => {});
let cancel = finished(process.stdin, (err?: Error | null) => {});
cancel();
cancel = finished(process.stdin, { readable: false }, (err?: Error | null) => {});
cancel();
pipeline(process.stdin, process.stdout, (err?: Error | null) => {});
@@ -168,6 +171,7 @@ function streamPipelineFinished() {
async function asyncStreamPipelineFinished() {
const fin = promisify(finished);
await fin(process.stdin);
await fin(process.stdin, { readable: false });
const pipe = promisify(pipeline);
await pipe(process.stdin, process.stdout);
+7 -1
View File
@@ -262,9 +262,15 @@ declare module "stream" {
class PassThrough extends Transform { }
interface FinishedOptions {
error?: boolean;
readable?: boolean;
writable?: boolean;
}
function finished(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, options: FinishedOptions, callback: (err?: NodeJS.ErrnoException | null) => void): () => void;
function finished(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, callback: (err?: NodeJS.ErrnoException | null) => void): () => void;
namespace finished {
function __promisify__(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream): Promise<void>;
function __promisify__(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, options?: FinishedOptions): Promise<void>;
}
function pipeline<T extends NodeJS.WritableStream>(stream1: NodeJS.ReadableStream, stream2: T, callback?: (err: NodeJS.ErrnoException | null) => void): T;
+5 -1
View File
@@ -163,7 +163,10 @@ function simplified_stream_ctor_test() {
}
function streamPipelineFinished() {
const cancel = finished(process.stdin, (err?: Error | null) => {});
let cancel = finished(process.stdin, (err?: Error | null) => {});
cancel();
cancel = finished(process.stdin, { readable: false }, (err?: Error | null) => {});
cancel();
pipeline(process.stdin, process.stdout, (err?: Error | null) => {});
@@ -172,6 +175,7 @@ function streamPipelineFinished() {
async function asyncStreamPipelineFinished() {
const fin = promisify(finished);
await fin(process.stdin);
await fin(process.stdin, { readable: false });
const pipe = promisify(pipeline);
await pipe(process.stdin, process.stdout);