Complete the code to import the Transform stream class from the 'stream' module.
const { [1] } = require('stream');The Transform class is imported from the 'stream' module to create transform streams.
Complete the code to create a new Transform stream that converts input chunks to uppercase.
const upperCaseTransform = new Transform({
transform(chunk, encoding, callback) {
this.push(chunk.toString().[1]());
callback();
}
});The toUpperCase() method converts the string chunk to uppercase.
Fix the error in the transform function to correctly handle asynchronous processing.
const delayTransform = new Transform({
async transform(chunk, encoding, callback) {
await new Promise(resolve => setTimeout(resolve, 100));
this.push(chunk);
[1]();
}
});The callback() function must be called to signal that the transform step is done.
Fill both blanks to create a Transform stream that filters out chunks shorter than 5 characters.
const filterShort = new Transform({
transform(chunk, encoding, callback) {
if (chunk.toString().[1] >= 5) {
this.push(chunk);
}
[2]();
}
});The length property gives the string length, and callback() signals completion.
Fill all three blanks to create a Transform stream that appends '!' to each chunk and converts it to a string.
const exclaimTransform = new Transform({
transform(chunk, encoding, callback) {
const modified = chunk.toString() + [1];
this.push(modified.[2]());
[3]();
}
});We append '!' (option A), convert to uppercase (option B), and call callback() (option C) to finish.