Using Nodejs Readable Stream push

I run the code in a command with node; This is an error when the code looks like this:

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

but this is a mistake:

> 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);

thank

+3
source share
1 answer

because if you are not using rs.push (null), then the cache is null, so rs calls ._read () to read.

if rs.push (null), the average value is satisfied.

+2
source

All Articles