Stream Readable Lab
Medium
0.0% Acceptance
In this lab, you will work with Node.js stream.Readable
to create a custom readable stream that reads data from a string. The stream will implement simple backpressure mechanisms to handle efficient data processing.
Streams, especially readable streams, are an essential part of Node.js, as they provide an efficient way to work with data in pieces. You will be tasked with creating a custom Readable
stream that reads data from a given string and maintains internal state to control the backpressure mechanism when the stream is piped to other streams.
Prerequisites
- Basic understanding of Node.js core modules.
- Knowledge of JavaScript classes, inheritance and asynchronous programming.
Hints
- You can extend the
Readable
stream and implement its internal_read()
method to read your data chunks. - Make use of the
readable.push()
method to push the data chunks into the readable stream. - The backpressure mechanism can be created by maintaining an internal counter to track the number of bytes read so far, and pausing or resuming the flow accordingly.
- Don't forget to use ESM imports/exports syntax for this lab.