Does readable.push() maintain a buffer in memory?

154 Views Asked by At

The documentation says that invoking readable.push(chunk) will cause data to be added to the internal queue for users to consume. Does that mean there is an internal buffer in the memory writing data until the buffer gets full, each time readable.push(chunk) gets invoked?

var Readable = require("stream").Readable;

var readable = new Readable();

var num = 1;

readable._read = function(size) {
    readable.push((num++).toString());
    if (num == 101) {
        readable.push(null);
    }
}

readable.pipe(process.stdout);

If that's what actually happens, can you explain me how the writable stream process.stdout works with that internal buffer? I know it also maintains its own buffer in the memory.

I understand I might have gotten everything wrong here from the beginning, but I'm trying to put everything together until I make myself clear with this concept.

Thanks!

0

There are 0 best solutions below