Creating readable and writable streams
Readable streams allow us to do such as representing infinite data series and out data that does not necessarily fit in memory, and much more. Writable streams can be created to connect with outputs that operate at the C level to control hardware (such as sockets), to wrap around other objects that aren't streams but nevertheless have some form of API to where data is pushed or to collect chunks together and potentially process them in batch.
In this recipe, we're going create readable and writable streams using the from2
and to2
modules. In the There's more... section, we'll discover how to do the equivalent with Node's core stream
module.
Getting ready
Let's create a folder called from2-to2-streams
, initialize it as a package, install the from2
and to2
modules, and create an index.js
file:
$ mkdir from2-to2-streams $ cd from2-to2-streams $ npm init -y $ npm install --save from2 to2 $ touch index.js
How to do it...
We'll start of by requiring from2...