Performance: Piping streams together
MEDIUM IMPACT
This affects how efficiently data flows through the application, impacting memory usage and CPU load during streaming operations.
const fs = require('fs'); const readable = fs.createReadStream('input.txt'); const writable = fs.createWriteStream('output.txt'); readable.pipe(writable);
const fs = require('fs'); const readable = fs.createReadStream('input.txt'); const writable = fs.createWriteStream('output.txt'); readable.on('data', chunk => { writable.write(chunk); }); readable.on('end', () => { writable.end(); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual event handling for streams | N/A | N/A | N/A | [X] Bad |
| Using stream.pipe() method | N/A | N/A | N/A | [OK] Good |