Complete the code to create a Buffer from a string.
const buf = Buffer.[1]('Hello');
The Buffer.from() method creates a new Buffer containing the given string.
Complete the code to read data from a readable stream into a Buffer.
stream.on('data', chunk => { const buf = Buffer.[1](chunk); });
Each chunk from a stream is a Buffer or can be converted to one using Buffer.from().
Fix the error in the code to properly concatenate multiple Buffer chunks from a stream.
let buffers = []; stream.on('data', chunk => { buffers.push(chunk); }); stream.on('end', () => { const result = Buffer.[1](buffers); });
Buffer.concat() combines an array of Buffers into one Buffer.
Fill both blanks to create a writable stream that writes Buffer data to a file.
const fs = require('fs'); const writable = fs.createWriteStream('output.txt'); writable.[1](Buffer.[2]('Data to write'));
The write method sends data to the writable stream, and Buffer.from() creates a Buffer from the string.
Fill all three blanks to read data from a readable stream, concatenate buffers, and convert to string.
let chunks = []; readable.[1]('data', chunk => { chunks.[2](chunk); }); readable.on('end', () => { const buffer = Buffer.[3](chunks); console.log(buffer.toString()); });
Use on to listen for data events, push to add chunks to array, and Buffer.concat to combine buffers.