data` event: Emitted by a readable stream to signal that data is available to be read. It's fired when the internal buffer has data.
readableevent: Emitted when there may be data to read from the stream. It doesn't guarantee that data is immediately available and is often used with manual reading using.read()`.
You need to pipe a file stream directly to an HTTP response. Which event would you listen to to forward each chunk as it arrives, and what would change if you used the other event instead?
If you attach a 'data' listener to a readable stream, what effect does that have on the stream's mode, and how would you switch it back to using the 'readable' event?
When reading from a TCP socket you notice chunks arriving in irregular sizes. Which event gives you finer control over when to read, and why would you pick it?
Your service processes large JSON log files line‑by‑line. Using the 'data' event caused memory spikes. Explain why moving to the 'readable' event can mitigate this and what code changes are needed.
During debugging you see that a stream's 'end' never fires when you have a 'data' listener attached. What could be causing this, and how would you verify the behavior using the 'readable' event?
You must implement backpressure when streaming data to a downstream API. How does handling the 'readable' event let you respect the downstream's write() return value compared to using 'data'?
Design a high‑throughput log ingestion pipeline that reads from dozens of file streams concurrently. Discuss how you would orchestrate reading using 'readable' versus 'data' events to maximize throughput while keeping memory usage bounded.
Your microservice must run on older Node versions that only emit 'data' and on newer versions that support async iteration. How would you abstract the stream handling to work efficiently across both, given the differences between the two events?
Explain the impact on CPU and garbage collection when processing a 10 GB file using the default 'data' flowing mode versus manually pulling chunks in 'readable' mode with a custom highWaterMark.
The organization is migrating a legacy pipeline that heavily relies on 'data' event streams to a new architecture based on async generators and explicit backpressure. Outline a migration strategy that refactors the code, validates correctness, and ensures performance parity, referencing the semantics of 'readable' vs 'data'.
Cross‑team, you need to define a streaming API contract that guarantees predictable memory usage. How would you specify the use of the 'readable' event and explicit read() calls in the API, and what guidelines would you set for downstream consumers to avoid pitfalls of the 'data' flowing mode?