Goal#
Extend the Streams API foundation with pipe operations and the byte-oriented variants needed to model network and binary I/O.
Depends on: "Implement Streams API foundation".
Scope#
- Pipe operations on
ReadableStreampipeTo(destination, options?)whereoptionsis{ preventClose, preventAbort, preventCancel, signal }pipeThrough({ readable, writable }, options?)AbortSignalintegration — aborting the signal aborts the pipe in both directions- Backpressure: do not pull until the destination's writer
readyresolves - Error propagation: errors on either side propagate based on
preventClose/preventAbort/preventCancel
tee()onReadableStream- Returns a two-element array of branches sharing one underlying source
- Both branches see the same chunks; closing/erroring is independent unless both cancel
- Byte streams
new ReadableStream({ type: 'bytes', ... })ReadableByteStreamController:enqueue(chunk: Uint8Array),close,error,desiredSize,byobRequestReadableStreamBYOBReader:getReader({ mode: 'byob' }),read(view)→Promise<{ value: Uint8Array, done }>,releaseLock,cancelReadableStreamBYOBRequest:view,respond(bytesWritten),respondWithNewView(view)- Auto-allocate path when constructor specifies
autoAllocateChunkSize
- Pull-throttling: byte stream controllers only call
pullwhile there is demand from a default reader (queued requests) or a BYOB reader (pending view requests)
Acceptance Criteria#
readable.pipeTo(writable)resolves when the source closes and the sink finishes draining, rejecting on either side's errorreadable.pipeThrough(transformStream)returns the transform'sreadableside and propagates errors- Aborting an
AbortSignalpassed topipeTocancels the source and aborts the sink (subject topreventCancel/preventAbort) tee()branches independently consume the same data; cancelling both branches cancels the source- BYOB reader returns
Uint8Arrayviews withbyteOffset/byteLengthmatching the bytes filled by the underlying source - Auto-allocate streams synthesize views of the configured size for the controller to fill
- Unit tests covering pipe error propagation in all 4 prevent-flag combinations, tee correctness with backpressure, BYOB read with both auto-allocate and consumer-provided views
- Conventions
cargo fmt --all --checkcargo clippy --workspace -- -D warningscargo test --workspace