workerd / compression
AGENTS.md8.8k starsChanged 9 months agoApache-2.0View on GitHub
An informal specification of the two Compression Streams classes as implemented in workerd, derived from — and kept in lockstep with — the test suite in this directory. The tests are the normative artifact. Both the C++ implementation (src/workerd/api/streams/compression.{h,c++}, built on internal streams over the shared api/compression.h CodecStage) and the TypeScript implementation (src/per_isolate/webstreams/compression.ts, behind typescript_implemented_streams) are covered. The two wrap the SAME C++ zlib codec (the TS pair drives utils.newCompressionCodec handles), so codec output is parity by construction; divergences live…
Trending
Quiet since August.thin dataabout the whole repository
Who's talking about cloudflare/workerd
- A Hacker News story“OS Workerd, Cloudflare's JavaScript/WASM Runtime”Hacker News · Sep 27, 2022 · 27 points
- withastro/astro“Cloudflare adapter returning [object Object]”GitHub · Oct 10, 2025 · 18 reactions
- supabase/supabase-js“The 'cache' field on 'RequestInitializerDict' is not implemented - Cloudflare Workers”GitHub · Mar 28, 2024 · 16 reactions
- nodejs/node“src: improve buffer.transcode performance”GitHub · Aug 1, 2024 · 13 reactions
- NixOS/nixpkgs“Package request: workerd”GitHub · Nov 12, 2024 · 12 reactions
The biggest 5 of 12 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 12
Talked about on GitHub, Bluesky and Hacker News (12 times).
On GitHub · 6
- Oct 10, 2025Cloudflare adapter returning [object Object] — withastro/astro18 reactions · 15 comments
- Mar 28, 2024The 'cache' field on 'RequestInitializerDict' is not implemented - Cloudflare Workers — supabase/supabase-js16 reactions · 24 comments
- Aug 1, 2024src: improve buffer.transcode performance — nodejs/node13 reactions · 26 comments
- Nov 12, 2024Package request: workerd — NixOS/nixpkgs12 reactions · 8 comments
- Feb 19, 2024Add Curve25519 — w3c/webcrypto9 reactions · 16 comments
1 more on GitHub
- Nov 3, 2025Optimize TextEncoder::encode — nodejs/performance7 reactions · 33 comments
On Bluesky · 4
- Mar 24, 2026workerd : le runtime JavaScript/Wasm open source de Cloudflare Workers — @news.humancoders.com4 likes and reposts
- Aug 22, 2026Current status: trying to build github.com/cloudflare/w... on various sandbox providers — @jeremymorrell.dev1 likes and repost
- Mar 24, 2026workerd : le runtime JavaScript/Wasm qui propulse Cloudflare Workers est maintenant open source. Basé sur les standards web, il permet… — @humancoders.com1 likes and repost
- Nov 5, 2024Technically workers are open source github.com/cloudflare/w... — @userops.bsky.social1 likes and repost
On Hacker News · 2
- Sep 27, 2022OS Workerd, Cloudflare's JavaScript/WASM Runtime27 points · 2 comments
- Oct 5, 2023Cloudflare workers is adopting Ada URL parser2 points
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository61 other files it gives its agents.
- AGENTS.mdAGENTS.md
- build/AGENTS.mdAGENTS.md
- src/cloudflare/AGENTS.mdAGENTS.md
- src/node/AGENTS.mdAGENTS.md
- src/per_isolate/AGENTS.mdAGENTS.md
- src/per_isolate/crypto/AGENTS.mdAGENTS.md
- src/per_isolate/webfs/AGENTS.mdAGENTS.md
- src/per_isolate/webstreams/AGENTS.mdAGENTS.md
- src/pyodide/AGENTS.mdAGENTS.md
- src/rust/AGENTS.mdAGENTS.md
- src/rust/cxx/AGENTS.mdAGENTS.md
- src/tests/node/AGENTS.mdAGENTS.md
- src/tests/node/http-client/AGENTS.mdAGENTS.md
- src/tests/node/http-server/AGENTS.mdAGENTS.md
- src/tests/node/net/AGENTS.mdAGENTS.md
- src/tests/node/stream/AGENTS.mdAGENTS.md
- src/tests/streams/AGENTS.mdAGENTS.md
- src/tests/streams/cache/AGENTS.mdAGENTS.md
- src/tests/streams/digest/AGENTS.mdAGENTS.md
- src/tests/streams/encoding/AGENTS.mdAGENTS.md
- src/tests/streams/formdata/AGENTS.mdAGENTS.md
- src/tests/streams/htmlrewriter/AGENTS.mdAGENTS.md
- src/tests/streams/identity/AGENTS.mdAGENTS.md
- src/tests/streams/inspect/AGENTS.mdAGENTS.md
- src/tests/streams/iocontext/AGENTS.mdAGENTS.md
- src/tests/streams/piping/AGENTS.mdAGENTS.md
- src/tests/streams/r2-patterns/AGENTS.mdAGENTS.md
- src/tests/streams/readable/AGENTS.mdAGENTS.md
- src/tests/streams/readable-byte/AGENTS.mdAGENTS.md
- src/tests/streams/scaling/AGENTS.mdAGENTS.md
- src/tests/streams/sockets/AGENTS.mdAGENTS.md
- src/tests/streams/strategies/AGENTS.mdAGENTS.md
- src/tests/streams/transform/AGENTS.mdAGENTS.md
- src/tests/streams/writable/AGENTS.mdAGENTS.md
- src/workerd/api/AGENTS.mdAGENTS.md
- src/workerd/api/crypto/AGENTS.mdAGENTS.md
- src/workerd/api/node/AGENTS.mdAGENTS.md
- src/workerd/api/streams/AGENTS.mdAGENTS.md
- src/workerd/io/AGENTS.mdAGENTS.md
- src/workerd/jsg/AGENTS.mdAGENTS.md
- src/workerd/server/AGENTS.mdAGENTS.md
- src/workerd/util/AGENTS.mdAGENTS.md
- types/AGENTS.mdAGENTS.md
- bazel-test-hygieneSkill
- commit-categoriesSkill
- dad-jokesSkill
- find-and-run-testsSkill
- identify-reviewerSkill
- investigation-notesSkill
- kj-styleSkill
- markdown-draftsSkill
- parent-project-skillsSkill
- pr-review-guideSkill
- receiving-code-reviewSkill
- rust-reviewSkill
- ts-styleSkill
- update-v8Skill
- wd-test-formatSkill
- workerd-api-reviewSkill
- workerd-safety-reviewSkill
- The first 60 shown.
The file
We split this AGENTS.md into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 52
Eager push: write() feeds the codec and settles when the codec has consumed the chunk — no read demand needed (not the identity rendezvous, …
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CompressionStream and DecompressionStream
An informal specification of the two Compression Streams classes as
implemented in workerd, derived from — and kept in lockstep with — the test
suite in this directory. The tests are the normative artifact. Both the
C++ implementation (src/workerd/api/streams/compression.{h,c++}, built on
internal streams over the shared api/compression.h CodecStage) and the
TypeScript implementation (src/per_isolate/webstreams/compression.ts,
behind typescript_implemented_streams) are covered. The two wrap the SAME
C++ zlib codec (the TS pair drives utils.newCompressionCodec handles), so
codec output is parity by construction; divergences live in the stream
wrappers.
The WPT compression/* tests already run against both implementations
(//src/wpt:compression and //src/wpt:compression-ts), so this suite
complements WPT: workerd-specific semantics (eager push, BYOB readable),
exact error identities and messages, the divergences, the strict-checks
flag axis, and real-HTTP body integration via the SELF loopback binding.
Interfaces
[Exposed=Worker]
interface CompressionStream {
constructor(DOMString format); // 'deflate' | 'gzip' | 'deflate-raw'
readonly attribute ReadableStream readable;
readonly attribute WritableStream writable;
};
[Exposed=Worker]
interface DecompressionStream {
constructor(DOMString format);
readonly attribute ReadableStream readable;
readonly attribute WritableStream writable;
};- Inheritance divergence (ledger #5): C++ subclasses
TransformStream; TypeScript is standalone.readable/writableplacement andconstructor.length(0 vs 1) follow (#5, #6). - The format is ToString-coerced exactly once (an object's
toStringruns once, both impls); a coerced string outside the three formats throwsTypeError"The compression format must be either 'deflate', 'deflate-raw' or 'gzip'." — but non-string arguments diverge (#7): TypeScript coercesundefinedinto that same validation failure, while the C++ jsg layer rejects it at the type boundary ("constructor parameter 1 is not of type 'string'.").nullcoerces to"null"in both. - The internal codec factory (
utils.newCompressionCodec) is never a JS-visible surface.
Core semantics
- Eager push: write() feeds the codec and settles when the codec has consumed the chunk — no read demand needed (not the identity rendezvous, not the encoding suite's HWM-0 demand-driven transform). Output buffers unboundedly on the readable side (TypeScript: the readable's queue, which the sink drains the codec's output into before the write settles; C++: the codec's buffer); a parked read is served as soon as any output exists (for deflate: the 2-byte zlib header from the first write, the rest at close-time flush).
- Delivery (#16): a default read receives a bounded piece of a write's
output — at most 64 KiB under TypeScript (the size of the chunks the sink
queues), the internal-stream read buffer under C++ (4 KiB; 16 KiB under
the
updated-auto-allocate-chunk-sizeautogate) — and a BYOB read fills its view in both. A write's output is never a single JS chunk, however large. Output produced before a trailing-junk error goes to the waiting reads first under TypeScript (one piece each; WPT decompression-extra-input); C++ rejects the waiting read (#17). - Snapshot at write: the codec consumes a copy taken synchronously inside write() (C++ adapter copy; TS strategy-size-callback snapshot). Post-write mutation/resize/detach cannot change what compresses; an already-detached chunk is a zero-byte no-op; shadowing metadata getters are never consulted.
- Chunks: ArrayBuffer, any view (offsets honored), empty and detached inputs are accepted by both. Strings (#1) and SharedArrayBuffers incl. SAB-backed views (#2) are accepted and encoded/copied by C++ but rejected by TypeScript per spec (Web IDL BufferSource without [AllowShared]). Everything else rejects with TypeError (#3 message) — after which the C++ stream SURVIVES (later writes flow, clean close) while TypeScript errors both sides, the spec's transform-time error propagation (#4). The TypeScript pair passes WPT's bad-chunks files; the C++ configuration disables compression-bad-chunks.
- Corrupt input (DecompressionStream): the WRITE rejects (TypeError "Decompression failed.") and both sides error, in both implementations; the failure propagates through downstream pipes to consumers.
- strict_compression_checks (pinned): trailing bytes after the member reject the write ("Trailing bytes after end of compressed data"); close() before the member completes rejects ("Called close() on a decompression stream with incomplete data") — including close with no data at all. Closing a CompressionStream with no writes emits a valid empty member.
- Backpressure accounting (#8): the C++ writer's
desiredSizeis inert (always 1); TypeScript counts the in-flight chunk against the default HWM 1 and recovers.writer.readyis settled in both (no sustained backpressure signal under eager settlement). - BYOB: the readable is byte-capable in both (legacy parity; WHATWG describes a default stream).
- Termination:
writer.abort(reason)errors both sides; a pending read receives the reason re-created across kj under C++ (same type/message withenhanced_error_serializationpinned, different instance) vs the original instance under TS (#9);writer.closedgets the ORIGINAL instance in both. Writes after abort: C++ closed-TypeError vs TS original reason (#10). Non-Error reasons are Error-ized by C++, delivered raw by TS (#11). The canceling reader's parked read: C++ rejects with the reason, TS resolves done (#12).readable.cancel()errors the writable under TS; C++ leaves it untouched —writer.closedstays pending (#13). - Reads: a second concurrent default read rejects under C++ ("single pending read request") and parks under TS (#14); the thenable check runs once per read under C++, twice under TS (#15). Under TS the first check runs inside the write delivering the chunk; a reader cancel from there stops the delivery and fails that write with the cancel reason (the writable errors per #13), where C++ has already settled the write.
- tee(): both branches observe identical bytes; the single-branch cancel promise carries the identity suite's ledger #13 semantics (C++ immediate, TS shared composite).
- Bodies: the four SELF-loopback tests drive compression through real HTTP serialization (close-signal propagation from JS streams into internal response-body writables) plus response-body decompression and multi-transform chains.
- The #6061 unhandled-rejection regression (Array.fromAsync over a failing
DecompressionStream) is pinned under
unhandled_rejection_after_microtask_checkpointin both cells.
Compatibility flags
The C++ cell pins every date-gated flag the implementation is subject to
(see the comment in compression-cpp.wd-test); the TS cell pins only
strict_compression_checks (consulted by the shared codec factory),
unhandled_rejection_after_microtask_checkpoint (isolate-level event
timing), and the internal-testing expose_draining_reader.
compression-cpp-pedantic.wd-test runs the full shared module set with the
dateless opt-in pedantic_wpt flag added to the main C++ cell's pinned
set, pinning the ABSENCE of pedantic effects: the compression classes'
internal-stream implementation consults the flag nowhere, and although the
pedantic-gated standard-streams machinery IS reachable from this suite's
surface (the pipe tests build real TransformStream sources), every
shared assertion holds unchanged — an enforced invariant against future
pedantic branches shifting anything the suite pins.
| Flag (enable date) | Selects | Unflagged behavior tested by |
strict_compression_checks (2023-08-01) | DS trailing-data + incomplete-close errors | legacy-nonstrict.js |
capture_async_api_throws (2022-10-31) | invalid chunk rejects instead of throwing synchronously | legacyInvalidChunkThrowsSynchronously |
unhandled_rejection_after_microtask_checkpoint (2026-03-03) | rejection-event timing the #6061 regression depends on | — |
| internal-stream flags (BYOB, abort queue, getters, tags, error serialization; see config comment) | generic internal-stream behaviors | identity suite legacy cell |
Divergence ledger (C++ vs TypeScript)
| # | Area | C++ | TypeScript | Pinned in |
| 1 | String chunks | accepted, UTF-8 encoded (the reason WPT compression-bad-chunks is disabled there) | rejected TypeError | stringChunkDiverges |
| 2 | SharedArrayBuffer / SAB-backed view chunks | accepted (copied out) | rejected TypeError (spec: BufferSource without [AllowShared]) | sharedArrayBufferChunkDiverges |
| 3 | Invalid-chunk TypeError message | "This TransformStream is being used as a byte stream, but received an object of non-ArrayBuffer/ArrayBufferView type on its writable side." | "The provided value is not of type (ArrayBuffer or ArrayBufferView)" | invalidChunkAftermathDiverges |
| 4 | Invalid-chunk aftermath | stream survives | both sides error (spec) | invalidChunkAftermathDiverges |
| 5 | TransformStream inheritance + accessor placement | subclass; readable/writable inherited | standalone; own accessors | transformStreamInheritance |
| 6 | constructor.length | 0 | 1 | constructorSurface |
| 7 | Missing/undefined format | jsg type-boundary TypeError ("not of type 'string'") | ToString-coerced into format validation | nonStringFormatThrows |
| 8 | desiredSize accounting | inert (always 1) | counts in-flight chunk, recovers | desiredSizeAccounting |
| 9 | Abort reason to pending read | re-created (same type/message, different instance) | original instance | abortReasonIdentity |
| 10 | Writes after abort | TypeError "This WritableStream has been closed." | original abort reason | writeAfterAbortDiverges |
| 11 | Non-Error abort reasons | Error-ized (string becomes message) | original value | nonErrorAbortReasonSurfacing |
| 12 | Canceling reader's parked read | rejects with the cancel reason | resolves done (WHATWG) | cancelSettlesPendingRead |
| 13 | readable.cancel() → writable side | untouched; writer.closed stays pending | errored; closed rejects with the reason | cancelReadableWritableAftermath |
| 14 | Second concurrent default read | TypeError "single pending read request" | parked, served in order | secondConcurrentRead |
| 15 | Thenable check per read resolution | once | twice | thenInterceptionDuringReadResolution |
| 16 | Default-read piece of a large buffered output | internal-stream read buffer (4 KiB; 16 KiB under updated-auto-allocate-chunk-size) | 64 KiB | largeOutputDeliveredInBoundedPieces |
| 17 | Output produced before a trailing-junk error, reads waiting | reads reject | each waiting read gets a piece, later reads error | trailingJunkAfterLargeOutput |
Assertion catalogue
| Module | Asserts |
api-surface.js | toStringTag branding; codec factory not exposed; side stability; inheritance/placement (#5); ctor name/length/source (#6); node:stream/web re-exports are the same classes; accessor brand checks |
construction.js | valid formats; invalid format exact message (case-sensitive); one-shot ToString coercion; non-string formats (#7) |
round-trip.js | all-formats round trips (compression verified smaller); parked-read service with pinned deflate bytes; shared pump/concat/readAll helpers |
chunk-boundaries.js | byte-at-a-time compression; 2-byte split decompression; all formats with 5-byte write chunks |
large-payload.js | 400KB patterned payload, chunked writes, byte-exact round trip |
empty-stream.js | close-with-no-writes emits a valid empty member; decompressing it yields EOF |
corrupt-input.js | write-time rejection with "Decompression failed."; both-sides error; iteration rejection; bad magic bytes |
strict-checks.js | trailing-data write rejection; close-with-no-data rejection; truncated-member close rejection |
chunk-types.js | BufferSource acceptance incl. offsets; string (#1), SAB (#2), invalid-chunk message+aftermath (#3, #4) |
buffer-lifecycle.js | snapshot-at-write: post-write mutation/detach/shrink invisible; already-detached no-op; detached/out-of-bounds typed-array and DataView views are no-ops; lying metadata getters never consulted |
byob.js | BYOB reader fills a 2-byte destination with the gzip magic |
backpressure.js | eager write settlement without reads; desiredSize accounting (#8) |
propagation.js | abort rejects pending read (reason per #9), errors both sides; cancel settles parked read (#12); write-after-abort (#10); non-Error reasons (#11); writes after a queued close reject (message per impl) without disturbing the close or output; cancel→writable aftermath (#13) |
reentrancy.js | thenable-check counts (#15); a reader cancel from a read result's then getter while the write is still delivering (TS: the write rejects with the reason, the writable errors per #13; C++: the write resolves, the writable is untouched per #13); second concurrent read (#14); close from a read continuation with round-trip integrity; sibling tee cancel from a continuation |
tee.js | branches byte-identical; single-branch cancel (identity ledger #13 semantics) with survivor draining |
draining-reader.js | TS only (C++ asserts absence): expectedLength undefined; a closed stream's backlog swept in ONE read with done — a small one, and a 1 MiB one as its sixteen 64 KiB pieces; lock/release |
delivery-shape.js | a 4 MiB single-write output read in bounded pieces (#16), byte-exact; BYOB views filled to their size; two pending reads take consecutive pieces (C++: #14); tee branches get bounded pieces; trailing junk after a large output with two reads waiting (#17) |
gc-interplay.js | writer abort after wrapper GC; decompression through collected wrapper (codec handle liveness) |
pollution.js | Object.prototype members (type, autoAllocateChunkSize, expectedLength, start, size, highWaterMark) reach neither the internal dictionaries nor a native body: a gzip round trip under pollution (neither implementation reads them) |
pipe-integration.js | compress→decompress chains from user and TransformStream sources; through IdentityTransformStream; bad-data propagation through both transform kinds |
body-integration.js | direct Response(cs.readable) body (same object, unlocked; byte-exact local arrayBuffer round trip); SELF-loopback HTTP: response-body decompression, multi-transform chain with completing pipeTo, compression/decompression pipelines into internal response bodies |
unhandled-rejection.js | #6061: no spurious unhandledrejection with Array.fromAsync |
which-impl.js | implementation detection |
Legacy (unflagged) behaviors
Guarded by compression-cpp-legacy.wd-test (C++ only,
generate_all_compat_flags_variant = False):
| Behavior | Asserted by |
| Trailing bytes after the member tolerated; member content delivered | legacyTrailingDataTolerated |
| close() with no data tolerated (empty output) | legacyCloseWithoutDataTolerated |
| close() mid-member tolerated | legacyTruncatedMemberCloseTolerated |
| Invalid chunk throws synchronously; the stream survives | legacyInvalidChunkThrowsSynchronously |
Generic pre-flag internal-stream behaviors (BYOB in-place fills, property
placement, [object Object] stringification) are guarded by the identity
suite's legacy cell and not repeated here.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

