fix: writeFile for buffers >= 2GiB - #261
Closed
dyk1454683243-sudo wants to merge 1 commit into
Closed
dyk1454683243-sudo wants to merge 1 commit into
dyk1454683243-sudo wants to merge 1 commit into
Conversation
Node's writeFile writeAll calls fs.write with the full buffer length. fs.write rejects length > INT32_MAX, so graceful-fs writeFile failed for buffers >= 2GiB while fs.promises.writeFile already chunks. Wrap the exported fs.write/writeSync to split large writes, matching current Node behavior. Fixes isaacs#256 Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
gracefulFS.writeFilefails for buffers of 2GiB or larger:Node's callback
writeFile(writeAll) calls the exportedfs.writewith the full buffer length.fs.writevalidateslengthas a signed 32-bit integer (uv_fs_write).fs.promises.writeFilealready chunks, which is why nativewriteFileworks on recent Node.graceful-fs wraps
writeFilefor EMFILE retry, butwriteAllstill calls the realfs.write, so the patched path hits this cap.Fix
Wrap the exported
fs.write/fs.writeSync(the functionswriteAllactually calls) and split binary writes larger thanINT32_MAX(2147483647). String writes and smaller buffers are unchanged.Tests
test/write-large-buffer.jsspies onfs.writeto prove chunking without requiring CI to write 2GiB. AwriteFilecase allocates a 2GiB buffer when possible and skips if allocation fails.Fixes #256