Wednesday, 3 May 2017

How to get chunks from a stream obtained from a string not from a file (Node.js)

When using fs.createReadStream method in Node.js on a file, I get a readable stream, on which a 'data' event is emitted. So, later on I can call myReadableStream.on('data', (chunk) => { ... } ), where I can get chunks of my stream, so it won't overheat the memory. The thing is, how do I split a stream into chunks when stream is created from the string not from the file? Now, I have a string that I convert into a readable object using require('stream').Readable, but when I call on('data'), I get only 1 chunk (I assume that there was no 'data' event emitted on a string converted into a readable stream, wasn't it?). The value of a stream derived from a file and of a stream derived from a string is the same (the same length), so I want it to be nicely split into a few chunks in order to speed up data processing. Could anyone help?



via user4447655

No comments:

Post a Comment