-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (25 loc) · 688 Bytes
/
index.js
File metadata and controls
31 lines (25 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const { createReadStream, createWriteStream } = require("fs");
const readStream = createReadStream("../stream/powder-day.mp4");
const writeStream = createWriteStream("./copy.mp4", {
highWaterMark: 1628920128,
});
readStream.on("data", (chunk) => {
const result = writeStream.write(chunk);
if (!result) {
console.log("backpressure");
readStream.pause();
}
});
readStream.on("error", (error) => {
console.log("an error occurred", error.message);
});
readStream.on("end", () => {
writeStream.end();
});
writeStream.on("drain", () => {
console.log("drained");
readStream.resume();
});
writeStream.on("close", () => {
process.stdout.write("file copied\n");
});