Skip to content

fs request: allow bigint values in read() and write() calls #21994

Closed
@ZaneHannanAU

Description

@ZaneHannanAU
  • Version: v10.7.0
  • Platform: Linux zeen3.localdomain 4.17.7-100.fc27.x86_64 deps: update openssl to 1.0.1j #1 SMP Tue Jul 17 16:29:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: fs

Currently working on an application that is likely to read & write from values greater than the 32-bit (technically 32 bit signed int) limit in fs.(read|write) and fs.promises.(read|write). Wanted to request that these functions be able to accept bigint values for reading/writing files >= 4GiB.

$ node
> let fh = await fs.promises.open('k.txt', 'r')
(node:6387) ExperimentalWarning: The fs.promises API is experimental
undefined
> await fh.read(Buffer.allocUnsafe(32), 0n, 32n, 32n)
await fh.read(Buffer.allocUnsafe(32), 0n, 32n, 32n)
^^^^^

SyntaxError: await is only valid in async function

> fh.read(Buffer.allocUnsafe(32), 0n, 32n, 32n)
Promise {
  <rejected> TypeError: Cannot mix BigInt and other types, use explicit conversions
    at read (internal/fs/promises.js:205:3)
    at FileHandle.read (internal/fs/promises.js:77:12)
    at repl:1:4
    at Script.runInThisContext (vm.js:91:20)
    at REPLServer.defaultEval (repl.js:321:29)
    at bound (domain.js:396:14)
    at REPLServer.runBound [as eval] (domain.js:409:12)
    at REPLServer.onLine (repl.js:619:10)
    at REPLServer.emit (events.js:187:15)
    at REPLServer.EventEmitter.emit (domain.js:442:20),
  domain:
   Domain {
     domain: null,
     _events:
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> (node:6387) UnhandledPromiseRejectionWarning: TypeError: Cannot mix BigInt and other types, use explicit conversions
    at read (internal/fs/promises.js:205:3)
    at FileHandle.read (internal/fs/promises.js:77:12)
    at repl:1:4
    at Script.runInThisContext (vm.js:91:20)
    at REPLServer.defaultEval (repl.js:321:29)
    at bound (domain.js:396:14)
    at REPLServer.runBound [as eval] (domain.js:409:12)
    at REPLServer.onLine (repl.js:619:10)
    at REPLServer.emit (events.js:187:15)
    at REPLServer.EventEmitter.emit (domain.js:442:20)
(node:6387) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6387) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

> $ type node
node is aliased to `node --experimental-repl-await --icu-data-dir=`echo -ne "$HOME"`/node_modules/full-icu'

Other than that; I'd request the allowing of bigint values in eg utimes(), lchmod(), flags, truncate(), mode, interval (on watchFile), highWaterMark (mostly just for consistency) and so on. It'd be a massive patch though; plus would likely make some parts incompatible (eg constants that are not pulling from fs.constants or process.binding('fs').constants).

Of course they shouldn't be using them but... people are human.

Metadata

Metadata

Assignees

Labels

feature requestIssues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions