Skip to content

Commit

Permalink
Removed legacy readable wrapper to workaround Node 14 stream issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Oct 2, 2023
1 parent a8832f6 commit 7466852
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 62 deletions.
21 changes: 9 additions & 12 deletions src/archive/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {Archive, Entry, IEntryInfo} from '../archive';
import {PathType} from '../types';
import {
streamToBuffer,
streamToReadable,
zipEfaToUnixMode,
zipPathIsMacResource,
zipPathTypeFromEfaAndPath
Expand All @@ -27,17 +26,15 @@ const yauzlEntryRead = async (zipfile: yauzl.ZipFile, entry: yauzl.Entry) => {
return null;
}

return streamToReadable(
await new Promise<Readable>((resolve, reject) => {
zipfile.openReadStream(entry, (err, stream) => {
if (err) {
reject(err);
return;
}
resolve(stream);
});
})
);
return new Promise<Readable>((resolve, reject) => {
zipfile.openReadStream(entry, (err, stream) => {
if (err) {
reject(err);
return;
}
resolve(stream);
});
});
};

/**
Expand Down
50 changes: 0 additions & 50 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Error>();
const errorsB = new Set<Error>();
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.
*
Expand Down

0 comments on commit 7466852

Please sign in to comment.