Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gracefulFS.writeFile fails for buffers with size equal or greater than 2GiB, while fs.writeFile can write arbitrary lengths on latest Node.js #256

Open
rotemdan opened this issue Oct 17, 2024 · 0 comments

Comments

@rotemdan
Copy link

rotemdan commented Oct 17, 2024

const largeBuffer = Buffer.alloc(2 ** 31)
const { promisify } = await import('node:util')
const { default: gracefulFS } = await import('graceful-fs')
const gracefulFSWriteFile = promisify(gracefulFS.writeFile)
await gracefulFSWriteFile('out', largeBuffer)

Errors with:

RangeError [ERR_OUT_OF_RANGE]: The value of "length" is out of range. It must be >= 0
&& <= 2147483647. Received 2147483648
    at Object.write (node:fs:848:5)
    at writeAll (node:fs:2224:6)
    at node:fs:2314:7
    at FSReqCallback.oncomplete (node:fs:188:23)
    at FSReqCallback.callbackTrampoline (node:internal/async_hooks:130:17) {
  code: 'ERR_OUT_OF_RANGE

On the other hand, with node's own writeFile, I can write arbitrary lengths:

Example (16 GiB buffer)

const largeBuffer = Buffer.alloc(2 ** 34) // 16 GiB buffer
const { writeFile } = await import('fs/promises')
await writeFile('out', largeBuffer)

(tested to work on Node v23.0.0, Windows 11)

Screenshot_1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant