InterviewSolution
Saved Bookmarks
| 1. |
Explain piping the streams? |
|
Answer» Piping is
No limit on piping operations. Example: Create a text file dataSinput.txt with the following content.
After executing the following code you can view the contents in the outputfile. var fs = require("fs"); //import fs module //creating a readstream to READ our inputdatafile dataSinput.txt var readStream = fs.createReadStream("F://dataSinput.txt"); //creating a writestream(initially empty) which is destination for transferred data var writeStream = fs.createWriteStream("F://dataSoutput.txt"); //Use Pipe command to transfer from readstream to writestream. //Pipe command takes all data from readstream and PUSHES it to writestream readStream.pipe(writeStream);Output in dataSoutput.txt can be seen as
|
|