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