workerd / webfs
AGENTS.md8.8k starsChanged 9 months agoApache-2.0View on GitHub
TypeScript reimplementation of the File System Access API's writable stream, needed when the typescript_implemented_streams compat flag is on. Parent directory conventions (primordials discipline, private-brand dispatch, no instanceof) apply — see src/per_isolate/AGENTS.md. FileSystemWritableFileStream is one of only two WritableStream subclasses in the runtime. When the streams flag swaps globalThis.WritableStream for the TypeScript class, a C++ subclass of the C++ WritableStream no longer passes the brand checks used by pipeTo, and instanceof WritableStream becomes false. Reimplementing the subclass in TypeScript is what…
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
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/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/compression/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
Files
src/per_isolate/webfs/
TypeScript reimplementation of the File System Access API's writable stream,
needed when the typescript_implemented_streams compat flag is on. Parent
directory conventions (primordials discipline, private-brand dispatch, no
instanceof) apply — see src/per_isolate/AGENTS.md.
WHY THIS EXISTS
FileSystemWritableFileStream is one of only two WritableStream subclasses in
the runtime. When the streams flag swaps globalThis.WritableStream for the
TypeScript class, a C++ subclass of the C++ WritableStream no longer passes
the brand checks used by pipeTo, and instanceof WritableStream becomes
false. Reimplementing the subclass in TypeScript is what restores the hierarchy.
The other subclass is DigestStream — see src/per_isolate/crypto/AGENTS.md.
CONSTRUCTION
This class has no user-callable constructor: instances come from
FileSystemFileHandle.createWritable(), a JSG method on a C++ type. So main.ts
installs two things, and both are required — replacing only the global leaves
createWritable() handing back C++ instances, and replacing only the method
leaves instanceof comparing against the wrong class.
createWritable is exported from writable-file-stream.ts and installed with
the same property attributes JSG_METHOD uses, so the swap is invisible to
property introspection. ts-webfs-writable-test.js's
createWritableDescriptorMatchesJsg holds that.
The install is also conditional on the webfs globals existing at all: the file
system is opt-in behind enable_web_file_system, and without it there is
nothing to replace.
THE C++ CONTRACT
writable-file-stream.ts owns only the stream wiring. The file semantics are a
native FileSystemWriteContextHandle (src/workerd/api/filesystem.h), reached
through utils.createFileSystemWriteContext(fileHandle, keepExistingData),
registered in src/workerd/io/per-isolate-bootstrap.c++ via the deliberately
filesystem-free declaration in src/workerd/api/filesystem-bootstrap.h.
The same context backs both implementations, so the file semantics are not
written twice and cannot drift. FileSystemWriteContextHandle::open() is shared
by the C++ createWritable() and the bootstrap factory; it returns the
DOMException rather than throwing it, because the two callers need it in
different shapes (see below).
Parts of the contract that are easy to break:
write(),seek()andtruncate()bypass the queue. They reach the context directly, as the C++ methods do, so a write is complete when its promise settles rather than when the queue drains. Chunks written through a writer (or bypipeTo) go through the sink instead, which lands in the same context.write()acquires and immediately releases a writer. That looks pointless but is what makes a stream already locked to a writer fail, and it is the C++ behavior.seek()andtruncate()deliberately do not, so they succeed on a locked stream.writeRejectsWhenLockedButSeekDoesNotpins the asymmetry, including the message, which says "reader" though the stream is writable.- Strings are NOT encoded on the TypeScript side. The file system writes
them as WTF-8, which
TextEncodercannot produce. Forward them to the context, exactly ascrypto/digest-stream.tsforwards toupdate(). - The two failure modes have different shapes. JSG unwraps arguments before
a method body runs, so a bad option bag is a synchronous throw while a file
that cannot be opened is a rejection.
createWritableis therefore deliberately not anasync function— that would turn the former into a rejection too. It classifies by exception type: a DOMException becomes a rejection, anything else is rethrown.badOptionsThrowSynchronouslyandcreateWritableRejectsForeignReceiverhold the two apart. - The option bag is coerced, not type-checked. JSG unwraps
jsg::Optional<bool>with ToBoolean, so{keepExistingData: 'false'}opts in. The TypeScript side reproduces this with!!, held bykeepExistingDataIsCoerced. - The write is transactional and holds a lock. Writes land in a temporary
file;
close()replaces the original's contents andabort()discards them, and the VFS lock is held fromcreateWritable()until one of them runs. A stream that is never closed nor aborted leaves the lock held until the context is collected.
PARITY
Both implementations run webfs-test.js unmodified, under webfs-test.wd-test
(C++) and webfs-ts-test.wd-test (TypeScript). Behavior shared between them
belongs in that file so drift fails one config or the other. TypeScript-only
behavior belongs in ts-webfs-writable-test.js.
ts-webfs-writable-test.js's isRealWritableStreamSubclass is the canary that
the main.ts install actually took effect; without it the rest of the suite
would pass against the C++ implementation too. pipeToWorks,
methodsAreBrandChecked and hasCorrectStringTag also fail against C++, so all
four are load-bearing.
The storage root is read-only. Tests that need to write must use the tmp
directory in it.
INTENTIONAL DIVERGENCES
Symbol.toStringTagis set unconditionally. JSG gates it on theset_tostring_tagcompat flag, so a worker with a compatibility date before that flag's 2024-09-26 default sees a tag here where the C++ implementation exposes none. This matches the rest of the TypeScript streams implementation, which also sets it unconditionally.- The option bag is read before the receiver is checked, the opposite of JSG's order. A call that is wrong in both ways reports the bag where C++ reports the receiver. Both are synchronous TypeErrors, so only the message differs.
ANTI-PATTERNS
- NEVER encode string chunks here; forward them to the context.
- NEVER reference
thisin the sink closures passed tosuper()— they are evaluated beforesuper()returns, whilethisis still in its temporal dead zone. Capture the context in a local first. - NEVER make
createWritableanasync function; it would collapse the two failure shapes into one. - NEVER declare
type: 'bytes'on the sink.webstreams/writable.tsrejects any non-undefinedtype, byte-oriented writable streams not being a thing in the standard.
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.

