-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPipe.js
More file actions
15 lines (11 loc) · 787 Bytes
/
Copy pathPipe.js
File metadata and controls
15 lines (11 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// pipe method allows us to pipe data from any readable stream to any writable stream
const { createWriteStream, createReadStream } = require('fs');
// ----- First example -------- //
// let readStream = createReadStream('./files/naruto.mp4'); // origin
// let writeStream = createWriteStream(`./files/copy${new Date().getTime()}.mp4`); // destination
// // The pipe method does the exact same things with our home made listeners and handles backpreasure for us
// readStream.pipe(writeStream).on("error", (err) => console.log(`Error occured`));
// ----- Second example -------- //
let writeStream = createWriteStream(`./files/myFile${new Date().getTime()}.txt`);
// piping the incoming stream to myFile... -> cmg echo "Hello berna" | node Pipe.js
process.stdin.pipe(writeStream);