Lazy Streams

Get an overview of the lazy streams.

Sometimes, we need to create a large number of streams at the same time, for example, to pass them to a function for further processing. A typical example is when using archiver, a package for creating archives such as TAR and ZIP. The archiver package allows us to create an archive from a set of streams, representing the files to add. The problem is that if we want to pass a large number of streams, such as from files on the filesystem, we would likely get an EMFILE, too many open files error. This is because functions like createReadStream() from the fs module will actually open a file descriptor every time a new stream is created, even before we start to read from those streams.

Get hands-on with 1200+ tech skills courses.