Complete the code to create a readable stream from a file.
const fs = require('fs'); const readable = fs.createReadStream([1]);
The createReadStream method needs the path of the file to read. Here, 'input.txt' is the correct file to read from.
Complete the code to pipe data from a readable stream to a writable stream.
readableStream.[1](writableStream);The pipe method connects a readable stream to a writable stream, sending data automatically.
Fix the error in the code to handle stream errors properly.
readableStream.on('error', [1]);
Using console.error is best to log errors clearly when a stream emits an error event.
Fill both blanks to create a writable stream and write data to it.
const writable = fs.createWriteStream([1]); writable.[2]('Hello, streams!');
Create a writable stream to 'output.txt' and use write to send data to it.
Fill all three blanks to create a transform stream that modifies data.
const { Transform } = require('stream');
const upperCaseTransform = new Transform({
transform(chunk, encoding, callback) {
this.push(chunk.toString().[1]());
callback();
}
});
readableStream.[2](upperCaseTransform).[3](writableStream);The transform stream converts data to uppercase using toUpperCase(). Then it pipes data from readable to transform, and from transform to writable.