refactor: simplify

This commit is contained in:
cha0s 2024-02-12 07:51:08 -06:00
parent 42cd174fcd
commit cb079dced4

View File

@ -46,8 +46,7 @@ exports.JsonStream.PrettyPrint = class extends exports.JsonStream {
};
exports.pipesink = (streamsOrStream) => {
const streams = Array.isArray(streamsOrStream) ? streamsOrStream : [streamsOrStream];
exports.pipesink = (stream) => {
class Sink extends Writable {
constructor() {
@ -63,11 +62,10 @@ exports.pipesink = (streamsOrStream) => {
}
const sink = new Sink();
const final = streams.reduce((output, input) => input.pipe(output));
return new Promise((resolve, reject) => {
final.pipe(sink);
final.on('error', reject);
final.on('end', () => {
stream.pipe(sink);
stream.on('error', reject);
stream.on('end', () => {
resolve(Buffer.concat(sink.buffers));
});
});