I’m stuck somehow, I have something like this in my code:
async function download() {
const source = createReadStreamSomeHow();
await pipeline(source, fs.createWriteStream("file.ext"));
return source;
}
I need to return the readable stream (source) and store it in an array somewhere and at the same time pipe the data from the read stream to “file.ext”. But when I call:
let task = await download();
taskArray.add(task);
the pipeline()
code pauses execution of the function, hence source is only returned when the data has been completely piped to “file.ext”.
Although I understand why the code behaves this way, I can’t seem to find a way to return the source stream from the download()
function and still pipe the data to “file.ext” at the same time. Is there a better way to achieve this and make it work? Thank for the help in advance.