Open lapo-luchini opened 1 year ago
I'm trying to decode a single file content to string using async iterators:
async function streamToString(stream) { // https://stackoverflow.com/a/63361543/166524 const chunks = []; for await (const chunk of stream) { chunks.push(Buffer.from(chunk)); } return Buffer.concat(chunks).toString("utf8"); } const stream = fs.createReadStream(proj) .pipe(unzipper.ParseOne(reFile)); const data = await streamToString(stream);
but it fails like this:
TypeError: stream is not async iterable
OTOH this works fine:
function streamToString(stream) { const chunks = []; return new Promise((resolve, reject) => { stream.on('data', chunk => chunks.push(chunk)); stream.on('error', err => reject(err)); stream.on('end', () => resolve(Buffer.concat(chunks).toString("utf8"))); }); }
I see that nodejs' Duplex itself had this bug two years ago, might this be related?
I'm trying to decode a single file content to string using async iterators:
but it fails like this:
OTOH this works fine:
I see that nodejs' Duplex itself had this bug two years ago, might this be related?