Goal#
Implement the four standard built-in transform streams that web pages most commonly use through the Streams API.
Depends on: "Implement Streams API foundation" and "Implement Streams API: pipeTo, pipeThrough, tee, and byte streams".
Scope#
TextDecoderStream- Constructor:
new TextDecoderStream(label = 'utf-8', options?)with{ fatal, ignoreBOM } - Wraps a streaming
TextDecoder(reusewe-encoding) readableproducesstringchunks;writableacceptsUint8Array/ArrayBuffer/ArrayBufferView- Handles boundary splits across multi-byte sequences (UTF-8, UTF-16)
encoding,fatal,ignoreBOMgetters
- Constructor:
TextEncoderStream- Constructor:
new TextEncoderStream() writableacceptsstringchunks,readableproducesUint8Arraychunks of UTF-8 bytes- Handles high-surrogate-then-low-surrogate splits across chunk boundaries
encodinggetter (always'utf-8')
- Constructor:
CompressionStream- Constructor:
new CompressionStream(format)whereformatis'gzip' | 'deflate' | 'deflate-raw' - Streaming DEFLATE compressor — reuse and, if necessary, extend the Phase 7 DEFLATE implementation in
we-imageto support streaming compression (move shared code into a smallwe-deflatemodule under an existing crate if cleaner; do not introduce a new crate dependency) - Emits zlib (
deflate) or gzip wrappers as appropriate
- Constructor:
DecompressionStream- Constructor:
new DecompressionStream(format) - Streaming DEFLATE decompressor reading the Phase 7 wrapper formats
- Constructor:
- All four streams must operate on a per-chunk basis with no full-buffering of input
Acceptance Criteria#
response.body.pipeThrough(new TextDecoderStream()).pipeTo(...)produces a stream of strings- Split-UTF-8 chunks (e.g. half of a 3-byte sequence per chunk) decode correctly without emitting replacement characters when not at end-of-stream
new Blob([...]).stream().pipeThrough(new CompressionStream('gzip'))round-trips throughDecompressionStream('gzip')to the original bytes'deflate'and'deflate-raw'formats round-trip- Invalid format strings throw
TypeErrorfrom the constructor - Unit tests: encoder/decoder boundary splits, all three compression formats with multi-chunk inputs, error on malformed compressed input
- Conventions
cargo fmt --all --checkcargo clippy --workspace -- -D warningscargo test --workspace- Zero external dependencies; streaming compressor implemented in pure Rust