From the course: Advanced Node.js
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Piping streams - Node.js Tutorial
From the course: Advanced Node.js
Piping streams
- [Instructor] You may be thinking to yourself that streams seem fun, but there's an awful lot of code that you have to use to implement a stream, and you have to worry about back pressure that seems a little complicated. Well I'm looking at our copy file that we created in the last lesson, and this is inside of the index.js file, found under chapter two, chapter two, lesson six, within the start folder. And what I'm gonna say is, we can actually just delete all of these handlers, because we don't need them. And I'm gonna delete this reference to a high water mark, because we also don't need it. I can pipe a read stream to a write stream, simply by typing readStream.pipe(writeStream). So again, what we're doing is the same thing. Instead of wiring up a bunch of listeners to listen for chunks of data and then pass those chunks of data into the write stream, the pipe method is doing it for us. The pipe method also automatically handles back pressure for us. The only thing that we didn't…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.