Skip to content

fs: Adjust default `length` for `fs.readSync` and fsPromises/`read`

Expands: https://github.com/nodejs/node/pull/40349

Context: default value of length changed from buffer.byteLength to buffer.byteLength - offset, because otherwise it would always be out of bounds when nonzero offset is set.

  • Implements doc-only change to Promises/filehandle.read
  • Adds same change to Synchronous/fs.readSync

Trivia: filehandle.read is slightly refactored to match its cousins.

  • fh.read(null) will assume default values (same as fh.read(), fh.read(undefined), fh.read({}), etc.) instead of throwing TypeError: Cannot read properties of null (reading 'buffer').
  • Default 16KB buffer will be redundantly checked for isArrayBufferView. Overhead should be negligible, and it only affects reads w/o preallocated buffer of desired size (i.e. where performance isn't considered).

Merge request reports

Loading