Monday 29 February 2016

Why use a 'while' when reading all the data from a non-flowing stream?

I don't really understand why we have to use a 'while' when reading all the current data in a readable stream. The documentation says that 'If you do not specify a size argument, then it will return all the data in the internal buffer.' Then why don't we just use a single read()?Example (from the doc):readable.on('readable', () => { var chunk; while (null !== (chunk = readable.read())) { console.log('got %d bytes of data', chunk.length); } });vsreadable.on('readable', () => { var chunk = readable.read(); if(chunk != null) { console.log('got %d bytes of data', chunk.length); } });Thanks!when the documentation says that 'If you do not specify a size argument, then it will return all the data in the internal buffer.'

Submitted February 29, 2016 at 08:16PM by vangelov

No comments:

Post a Comment