Skip to content

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

Description

@rotemdan
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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions