Repository navigation
Description
What is the problem this feature will solve?
Currently, all Node.js fs module methods for writing data (such as fs.write, fs.createWriteStream) only accept Buffers or strings. There is no built-in support for writing data directly from Blob or web ReadableStream sources. This limits interoperability with web platform APIs and makes working with large files or streaming data @less seamless, especially when trying to move data efficiently from web contexts into the filesystem. Furthermore, Node.js provides fs.readableWebStream, but no corresponding fs.createWritableStream that would allow writing from web streams or Blobs directly.
What is the feature you are proposing to solve the problem?
Extend the Node.js fs module with the following capabilities:
- Allow fs.write and related write methods to accept Blob objects as a valid input, making it possible to write the entirety of a Blob's contents to a file without manual conversion to Buffer.
- Introduce fs.createWritableStream (web-compatible), which would be a direct counterpart to fs.readableWebStream and support writing from web ReadableStream sources to files.
This would improve ease-of-use when working with large binary/web platform data and make fs more aligned with modern web standards.
What alternatives have you considered?
Current workarounds involve manually converting Blobs and web streams into Buffers or converting web streams into node:streams
The only solution we have today is to use the fs.promise.writeFile(path, webStream) which luckily supports async iterable
with that in mind, the NodeJS document for...
... filehandle.appendFile(data[, options]) says it support:
data: <string> | <Buffer> | <TypedArray> | <DataView> | <AsyncIterable> | <Iterable> | <Stream>
it should also say
data: <string> | <Buffer> | <TypedArray> | <DataView> | <AsyncIterable> | <Iterable> | <Stream> | <ReadableStream>
or just
data: <string> | <Buffer> | <TypedArray> | <DataView> | <AsyncIterable> | <Iterable>
as stream's are async iterable
and i also do not thing it should say Buffer anymore... buffer is a typed array already... so it can just say:
data: <string> | <TypedArray> | <DataView> | <AsyncIterable> | <Iterable>
but this is just only off-topic
able to write Blob's would enable efficient native copy operations (like using openAsBlob(path) and writing directly to another file) without data passing through the JS runtime.
able to write blobs avoids extra conversions/allocations in JS, reduces memory footprint and GC pressure
the solution i'm looking for is something like:
blob = new Blob(['hello world'])
await filehandle.write(blob)
await blob.stream().pipeTo(fs.createWritableStream(dest))
// using fetch is becoming more popular, so a web writable stream is highly requested
await new Response('...').body.pipeTo(fs.createWritableStream(dest))Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsAwaiting Triage
Activity
aelhor commentedon Feb 8, 2026
Hi @jimmywarting,
I’m interested in working on this. I've recently been working on the stream internals (specifically destruction propagation in DuplexPair),
I see a few different paths mentioned in the proposal. Would you prefer a PR that starts with the documentation/type updates for fs.promises.writeFile (confirming it already supports ReadableStream), or are you looking for a prototype to add native Blob support to the fs write methods first?
I'd love to hear which part you think is the highest priority for a first step.
jimmywarting commentedon Feb 12, 2026
Hi @aelhor
That's the least of my worries. It already supports it so... not needed as much.
Yes, more like it... this is kind of what I'm looking for. Preferably the part where the reading/writing doesn't really need to touch the JavaScript runtime at all. (I acknowledge that this require differentiating what blob's are backed up by the file system and those created from memory that makes it have to work a bit differently depending on what kind of blob is being written)
☝️ This should basically just be a
copyFileoperation and it should be nearly as fast asfs.promises.copyFile(src, dest). preferable with COPYFILE_FICLONE flag (copy on write)this would only work for blob's backed up by the file system (not dose created from memory)
my next question now becomes: should
copyFilesupport blob also?copying files should(?) also be faster than:
which requires(?) the data to touch the JavaScript runtime with extra overhead:
This means it can't optimize native
.pipe()with sendfile/copy_file_range because it:(I don't know if this is true, but it might as well be... maybe Node.js is already optimizing native stream to native stream, I don't know the internals) but it would be great if it could
If Node.js now can optimize things to not have to touch the JS runtime, then it should work for web streams as well.
I also think these three should have nearly the same speed:
And so should these two:
To move forward, here are some sub-issues:
fs.promises.writeFile(),filehandle.write(), andfilehandle.appendFile()initially fs.promise and fs with callbacks might only support blob initially? I think reading blob's in a sync manner might be problematic. technically a blob from fs.openAsBlob might be coming from a network, a browserified node:fs polyfill version might have problem doing sync stuff also - so writing blob in a sync manner should be not be possible ❌
Optimize Blob-to-file writes for native copy operations - When writing a Blob from
openAsBlob(), bypass JS runtime and use native copy operations (sendfile/copy_file_range) for performanceImplement
fs.createWritableWebStream()- Create a web-compatible WritableStream counterpart tofs.readableWebStream()for writing to filesUpdate documentation and types for existing AsyncIterable/ReadableStream support - Clarify that
fs.promises.writeFile()already supports web ReadableStream and update TypeScript definitions accordinglyUpdate documentation types for existing Write methods where it mention Buffer type - instead of saying something supports Buffer as a type it should instead just say TypedArray or Uint8Array
Honestly, I don't mind what you start working on first - whatever gets the ball rolling! Start with the easiest one first 🤷♂️
Let me know if you'd like me to create these as separate issues to help organize the work.
another thing that bugs me a tiny bit is that there isn't any
openAsBlob in fs.promise- add a TODO for this?aelhor commentedon May 16, 2026
Hi @jimmywarting
I will work on this over the next few days. I will get here with an update. I hope we can cooperate
aelhor commentedon Jul 19, 2026
As promised, I've started on it with a focused first PR that adds Blob support to the writeFile / appendFile family (both fsPromises and FileHandle variants): #64611
Before tackling the remaining parts, I'd like input on two open design questions:
1. filehandle.write(blob) (positional write)
The existing overloads: filehandle.write(buffer, offset, length, position) and filehandle.write(string[, position[, encoding]]) are low-level and positional. Adding Blob support here raises a few questions:
2. fs.createWritableStream (web writable stream)
Happy to spin either of these off into separate issues if that's preferred for tracking.
github-actions commentedon Nov 22, 2026
This issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.