diff --git a/src/archive/zip.ts b/src/archive/zip.ts index 6d93dc8..17a6eaf 100644 --- a/src/archive/zip.ts +++ b/src/archive/zip.ts @@ -8,7 +8,6 @@ import {Archive, Entry, IEntryInfo} from '../archive'; import {PathType} from '../types'; import { streamToBuffer, - streamToReadable, zipEfaToUnixMode, zipPathIsMacResource, zipPathTypeFromEfaAndPath @@ -27,17 +26,15 @@ const yauzlEntryRead = async (zipfile: yauzl.ZipFile, entry: yauzl.Entry) => { return null; } - return streamToReadable( - await new Promise((resolve, reject) => { - zipfile.openReadStream(entry, (err, stream) => { - if (err) { - reject(err); - return; - } - resolve(stream); - }); - }) - ); + return new Promise((resolve, reject) => { + zipfile.openReadStream(entry, (err, stream) => { + if (err) { + reject(err); + return; + } + resolve(stream); + }); + }); }; /** diff --git a/src/util.ts b/src/util.ts index b89a006..6439afa 100644 --- a/src/util.ts +++ b/src/util.ts @@ -250,56 +250,6 @@ export async function streamReadEnd( }); } -/** - * Create readable stream from another readable stream. - * Useful for converting an active stream into an pending stream. - * - * @param stream Readable-compatible stream. - * @returns Readable stream. - */ -export function streamToReadable(stream: Readable) { - // Pause stream, resumed only when needed. - stream.pause(); - - // Create readable. - const r = new Readable({ - /** - * Read method. - */ - read: () => { - stream.resume(); - } - }); - - // Forward data and end. - stream.on('data', d => { - r.push(d); - stream.pause(); - }); - stream.on('end', () => { - r.push(null); - }); - - // Forward errors both ways. - const errorsA = new Set(); - const errorsB = new Set(); - stream.on('error', err => { - if (errorsA.has(err)) { - return; - } - errorsA.add(err); - r.emit('error', err); - }); - r.on('error', err => { - if (errorsB.has(err)) { - return; - } - errorsB.add(err); - stream.emit('error', err); - }); - return r; -} - /** * Wrapper for lchmod, does nothing on unsupported platforms. *