1. Readable source
createReadStream returns a Readable that emits the file's contents as a sequence of chunks.
const src = createReadStream("in.txt");Typorithm · medium
Step 1 of 8 · intro card
Streams
Streams process data in chunks instead of loading a whole file into memory. createReadStream is a Readable, createWriteStream a Writable; .pipe() wires source to destination and handles backpressure automatically, keeping memory constant for any file size.
A stream processes data in chunks rather than reading an entire file into memory at once, so memory stays constant no matter how large the file is.
createReadStream produces a Readable (the source of chunks) and createWriteStream produces a Writable (the sink). Calling src.pipe(dst) wires the two together.
.pipe() pulls chunks from the source and pushes them into the destination, automatically applying backpressure so a slow Writable never overwhelms memory. The "end" event fires when the source is exhausted.
createReadStream is a Readable; createWriteStream is a Writable.
.pipe() wires source → destination and handles backpressure.
The "end" event fires when the source is exhausted.
import { createReadStream, createWriteStream } from "node:fs";
const src = createReadStream("in.txt");
const dst = createWriteStream("out.txt");
src.pipe(dst);
src.on("end", () => console.log("done"));Connect each part of the code to the concept before you type.
createReadStream returns a Readable that emits the file's contents as a sequence of chunks.
const src = createReadStream("in.txt");createWriteStream returns a Writable that consumes chunks and writes them to the file.
const dst = createWriteStream("out.txt");.pipe() connects the Readable to the Writable and manages backpressure automatically.
src.pipe(dst);The "end" event fires once the Readable has emitted all of its data.
src.on("end", () => console.log("done"));Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.