Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs Readable Stream push usage

Tags:

stream

node.js

I run some code in command with node; It's on error when the code like this:

> var rs = new require('stream').Readable();
> rs.push("123");rs.push(null); // two pushes are in the same row;

but this is error:

> var rs = new require('stream').Readable();
> rs.push("123");  // I went them are not in the same row;
// then get a error, like :
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: not implemented
    at Readable._read (_stream_readable.js:446:22)
    at Readable.read (_stream_readable.js:320:10)
    at maybeReadMore_ (_stream_readable.js:431:12)
    at _stream_readable.js:422:7
    at process._tickCallback (node.js:415:13)

I need code like this:

var rs = new require('stream').Readable();
rs.pipe(someWriteAbleStream)
// some time later
rs.push(somedata);
// some time late
rs.push(somedata);
// ...
rs.push(null);

Thanks;

like image 524
user3305221 Avatar asked Jul 20 '26 22:07

user3305221


1 Answers

because , if you no rs.push(null), then cache is null, so rs call ._read() to read.

if rs.push(null) , mean is done.

like image 150
user2434831 Avatar answered Jul 22 '26 14:07

user2434831



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!