Complete the code to create a readable stream from a file.
const fs = require('fs'); const readable = fs.createReadStream('[1]');
The fs.createReadStream function needs the input file name to read data from. Here, 'input.txt' is the correct file to read.
Complete the code to pause the readable stream when the buffer is full.
readable.on('data', (chunk) => { if (!writable.write(chunk)) { readable.[1](); } });
The pause() method pauses the readable stream to apply backpressure when the writable stream buffer is full.
Fix the error in the code to resume the readable stream when the writable stream drains.
writable.on('drain', () => { readable.[1](); });
The resume() method restarts the readable stream after it was paused due to backpressure.
Fill both blanks to correctly handle backpressure in a pipe.
readable.on('data', (chunk) => { if (!writable.[1](chunk)) { readable.[2](); } });
The write() method writes data to the writable stream. If it returns false, the readable stream should pause() to apply backpressure.
Fill all three blanks to create a backpressure-aware stream pipe.
readable.on('data', (chunk) => { if (!writable.[1](chunk)) { readable.[2](); } }); writable.on('[3]', () => { readable.resume(); });
This code writes chunks to the writable stream. If write() returns false, it pauses the readable stream. When the writable stream emits drain, it resumes the readable stream.