-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path3-writable.js
More file actions
27 lines (21 loc) · 562 Bytes
/
Copy path3-writable.js
File metadata and controls
27 lines (21 loc) · 562 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
'use strict';
const fs = require('node:fs');
const stream = require('node:stream');
async function* dup(char, size) {
let counter = 0;
while (counter++ < size) {
// throw new Error('Error generating data');
yield char;
}
}
const readable = stream.Readable.from(dup('A', 1_000_000));
const writable = fs.createWriteStream('data.tmp');
readable.on('data', (data) => {
writable.write(data);
});
readable.on('error', (error) => {
console.log({ readable: error });
});
writable.on('error', (error) => {
console.log({ writable: error });
});