Skip to content

fs: add Blob support to writeFile and appendFile#64611

Open
aelhor wants to merge 1 commit into
nodejs:mainfrom
aelhor:fs-writefile-blob
Open

fs: add Blob support to writeFile and appendFile#64611
aelhor wants to merge 1 commit into
nodejs:mainfrom
aelhor:fs-writefile-blob

Conversation

@aelhor

@aelhor aelhor commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

the issue actually asks. Use this corrected body instead:
This PR addresses part of #61684 by adding Blob support to the writeFile / appendFile family:

  • fsPromises.writeFile(data)
  • fsPromises.appendFile(data) (also broadens the documented data union from {string|Buffer} to the full set)
  • filehandle.writeFile(data)
  • filehandle.appendFile(data)

Implementation

A Blob is converted to a web ReadableStream via blob.stream() and consumed through the existing async-iterable path in writeFile. This is a small, ~6-line change that reuses existing infrastructure. Native zero-copy via a C++ blob handle is explicitly deferred as future work.

Tests

New test/parallel/test-fs-writefile-blob.js covers all 4 entry points, plus empty blob, binary blob, large blob (multi-chunk), explicit encoding option, and AbortSignal cancellation.

Scope: this covers the writeFile/appendFile portion of the issue's first ask. Remaining items from #61684 (the positional filehandle.write(blob), and the web fs.createWritableStream counterpart) will be tracked as separate follow-up PRs to keep this focused.

Refs: #61684

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Jul 19, 2026
Allow writeFile() and appendFile() (and their FileHandle
variants) to accept a Blob, converting it to a web
ReadableStream via blob.stream().

Signed-off-by: Ahmed Elhor <aelhor90@gmail.com>
@aelhor
aelhor force-pushed the fs-writefile-blob branch from d6945db to e8258fd Compare July 20, 2026 22:48
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.13%. Comparing base (00917ba) to head (e8258fd).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64611      +/-   ##
==========================================
- Coverage   90.14%   90.13%   -0.02%     
==========================================
  Files         741      741              
  Lines      242076   242081       +5     
  Branches    45558    45553       -5     
==========================================
- Hits       218216   218190      -26     
- Misses      15385    15401      +16     
- Partials     8475     8490      +15     
Files with missing lines Coverage Δ
lib/internal/fs/promises.js 93.01% <100.00%> (+0.01%) ⬆️

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants