I only recently noticed that the following code is not doing what it was doing earlier… actually writing the file to the disk.
const download = async (archive) => {
const d = await new Promise((resolve) => {
const opts = { method: 'GET' };
const req = https.request(url, opts, (res) => {
const file = fs.createWriteStream(`path/to/${archive}`);
res.on('data', (chunk) => {
file.write(chunk);
//process.stdout.write(chunk);
})
.on('end', () => file.end());
resolve(archive);
});
req.on('error', (error) => console.error(error));
req.end();
});
}
the file is getting created on disk, but is only 0B
. If I uncomment process.stdout.write(chunk)
, it happily spits out gobbledegook of the binary file to the console. But nothing is actually written to the disk.
Where am I goofing up? or has something changed in node
recently that is silently screwing up my code? Very happy for any guidance.