Streaming lets you handle data bit by bit instead of all at once. This helps when working with large files or slow networks.
Reading a large file without loading it fully into memory.
Sending data over the network as it becomes available.
Processing live data like video or audio streams.
Transforming data on the fly while copying it.
Saving memory and improving performance with big data.
Syntax
Deno
const readable = new ReadableStream({
start(controller) {
// push data chunks with controller.enqueue()
// call controller.close() when done
}
});
const writable = new WritableStream({
write(chunk) {
// handle each chunk of data
},
close() {
// cleanup when done
}
});
ReadableStream produces data chunks you can read.
WritableStream accepts data chunks you can write to.
Examples
This creates a readable stream that sends two text chunks then ends.
This connects the readable stream to the writable stream, sending data automatically.
Deno
readable.pipeTo(writable);
Sample Program
This program creates a readable stream that sends three text chunks. The writable stream logs each chunk it receives and a message when the stream ends. The pipeTo method connects them so data flows automatically.
The write method calls chunk.toUpperCase(), which only works on strings.
Step 2: Analyze the write call argument
The code writes the number 123, which has no toUpperCase() method, causing a runtime error.
Final Answer:
Cannot call toUpperCase on a number -> Option D
Quick Check:
toUpperCase on number causes error = A [OK]
Hint: Check data types before calling string methods [OK]
Common Mistakes:
Assuming write must be async
Thinking getWriter() is invalid
Missing await on WritableStream creation
5. You want to transform a ReadableStream of text chunks to uppercase and write them to a WritableStream. Which approach correctly implements this in Deno?
hard
A. Pipe the readable through a TransformStream that uppercases chunks, then pipe to writable
B. Directly write chunks from readable to writable without transformation
C. Use readable.getReader() and writable.getWriter(), but forget to release locks
D. Convert chunks to uppercase after writing to writable
Solution
Step 1: Understand stream transformation
To modify data between readable and writable, use a TransformStream that changes chunks to uppercase.
Step 2: Use pipeThrough and pipeTo methods
Pipe the readable stream through the transform, then pipe the result to the writable stream for correct flow and backpressure handling.
Step 3: Evaluate other options
Directly write chunks from readable to writable without transformation skips transformation, C risks locking issues, and D transforms too late after writing.
Final Answer:
Pipe the readable through a TransformStream that uppercases chunks, then pipe to writable -> Option A
Quick Check:
Use TransformStream + pipeThrough + pipeTo = B [OK]
Hint: Use TransformStream between readable and writable for data changes [OK]
Common Mistakes:
Skipping TransformStream for data modification
Not handling stream locks properly
Transforming data after writing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.