From 46f3f013b500653ebb1803ffff01d7eb6d75e10f Mon Sep 17 00:00:00 2001 From: Jackson Delahunt Date: Fri, 5 Oct 2018 03:35:14 +1000 Subject: [PATCH] unzipper: autodrain promise (#29281) * update autodrain type * add test --- types/unzipper/index.d.ts | 6 ++++-- types/unzipper/unzipper-tests.ts | 14 ++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/types/unzipper/index.d.ts b/types/unzipper/index.d.ts index 43c50e1818..4e5b641eed 100644 --- a/types/unzipper/index.d.ts +++ b/types/unzipper/index.d.ts @@ -7,7 +7,7 @@ // TypeScript Version: 2.2 /// -import { Readable, Stream, PassThrough, Duplex } from "stream"; +import { Readable, Stream, PassThrough, Duplex, Transform } from "stream"; import { ClientRequest, RequestOptions } from "http"; export interface PullStream extends Duplex { @@ -16,7 +16,9 @@ export interface PullStream extends Duplex { } export interface Entry extends PassThrough { - autodrain(): Promise; + autodrain(): Transform & { + promise(): Promise; + }; buffer(): Promise; path: string; diff --git a/types/unzipper/unzipper-tests.ts b/types/unzipper/unzipper-tests.ts index 26cebebdef..68464d5451 100644 --- a/types/unzipper/unzipper-tests.ts +++ b/types/unzipper/unzipper-tests.ts @@ -1,8 +1,14 @@ -import { Parse, Open, Entry, CentralDirectory } from "unzipper"; +import { createReadStream } from 'fs'; +import { get } from 'http'; +import { CentralDirectory, Entry, Open, Parse } from 'unzipper'; -import { createReadStream } from "fs"; - -import { get } from "http"; +createReadStream("http://example.org/path/to/archive.zip") + .pipe(Parse()) + .on("entry", (entry: Entry) => { + entry.autodrain().promise().then(() => { + console.log("Finished draining stream"); + }); + }); createReadStream("http://example.org/path/to/archive.zip") .pipe(Parse())