unzipper: autodrain promise (#29281)

* update autodrain type

* add test
This commit is contained in:
Jackson Delahunt
2018-10-05 03:35:14 +10:00
committed by Wesley Wigham
parent 6b987fa09f
commit 46f3f013b5
2 changed files with 14 additions and 6 deletions

View File

@@ -7,7 +7,7 @@
// TypeScript Version: 2.2
/// <reference types="node" />
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<void>;
autodrain(): Transform & {
promise(): Promise<void>;
};
buffer(): Promise<Buffer>;
path: string;

View File

@@ -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())