sindresorhus / get-stream

Get a stream as a string, Buffer, ArrayBuffer or array
MIT License
341 stars 33 forks source link

Fails to read buffer if `readable` listener is already present #46

Closed szmarczak closed 1 year ago

szmarczak commented 3 years ago
import {PassThrough} from 'stream';
import getStream from 'get-stream';

const s = new PassThrough();
const g = getStream.buffer(s);

s.on('readable', () =>{
    console.log('readable');
});

s.push('foobar');
s.push(null);

console.log(await g);

Result:

readable
readable

Expected:

+foobar
szmarczak commented 3 years ago

Seems like a Node.js fault. This gives the same result:

import {PassThrough, pipeline} from 'stream';

const first = new PassThrough();
const second = new PassThrough();

first.on('readable', () =>{
    console.log('readable');
});

pipeline(first, second, error => {
    console.log(`finished! error=${error}`);
});

first.push('foobar');
first.push(null);

second.resume();
szmarczak commented 3 years ago

https://github.com/nodejs/node/issues/40256

ehmicky commented 1 year ago

Since this is a problem with Node.js itself, should this be closed? This library just iterates over the stream, it does not do anything special related to the above behavior.