node
node copied to clipboard
fs: adjust `position` validation in reading methods
This PR:
- Adds validation of
position
argument tofilehandle.read()
, same as in cousin methods - Allows bigint position for
filehandle.read()
- Adjusts min number position from
Number.MIN_SAFE_INTEGER
to-1
- Adjusts min bigint position from
-2⁶³
to-1
- Adjusts max bigint position from
2⁶³ - 1
to2⁶³ - 1 - length
- Makes docs a bit more pedantic
Tests are still passing and documented features are still working, but there are potentially breaking changes:
- When user passes an unsafe number or not a number in
filehandle.read()
, an exception is thrown.- Previously: silently read from current position.
- When user passes a safe bigint in
filehandle.read()
, it works.- Previously: silently read from current position.
- When user passes a negative integer (except for
-1
or-1n
which explicitly means current position), an exception is thrown.- Previously: silently read from current position.
- When user passes a bigint close to upper limit (
2⁶³ - 1
), and addinglength
breaks this limit, an exception is thrown.- Previously:
EINVAL
fromread(2)
(platform-dependent)
- Previously:
When user passes a bigint close to upper limit (
2⁶³ - 1
), and addinglength
breaks this limit, an exception is thrown.
- Previously:
EINVAL
fromread(2)
Could we land this as a semver-patch first, then the rest of this PR as https://github.com/nodejs/node/labels/semver-major?
Moved strikethrough parts in a separate PR. I'll rebase when that lands.
Edit: when https://github.com/nodejs/node/pull/42999 lands. 😅
@LiviaMedeiros this needs a rebase.
CI: https://ci.nodejs.org/job/node-test-pull-request/46510/
This is https://github.com/nodejs/node/labels/semver-major, it needs at least two approving reviews from @nodejs/tsc.
@nodejs/fs
@LiviaMedeiros this needs another rebase.
Thanks for reminding!
CI: https://ci.nodejs.org/job/node-test-pull-request/46584/
CI: https://ci.nodejs.org/job/node-test-pull-request/46633/
This needs another rebase.
CI: https://ci.nodejs.org/job/node-test-pull-request/47145/
Ping @nodejs/tsc @nodejs/fs for reviews.
I think this deserves changes
entries in the docs?
Agreed, added bigint support as changes
entry.
Other adjustments are fixes in undocumented/cornercase behaviors.
Ping @nodejs/tsc @nodejs/fs for reviews.
Can we run some benchmarks on these paths?
AFAICT no merge conflicts happened since last time, but I'll rebase and rerun CI tomorrow to be safer.
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1385/
CI: https://ci.nodejs.org/job/node-test-pull-request/53956/
CI: https://ci.nodejs.org/job/node-test-pull-request/53961/
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1387/
Results
confidence improvement accuracy (*) (**) (***)
fs/bench-mkdirp.js n=10000 1.10 % ±1.86% ±2.45% ±3.16%
fs/bench-opendir.js bufferSize=1024 mode='async' dir='lib' n=100 0.39 % ±1.99% ±2.63% ±3.38%
fs/bench-opendir.js bufferSize=1024 mode='async' dir='test/parallel' n=100 -0.89 % ±1.30% ±1.71% ±2.20%
fs/bench-opendir.js bufferSize=1024 mode='callback' dir='lib' n=100 1.87 % ±1.97% ±2.60% ±3.35%
fs/bench-opendir.js bufferSize=1024 mode='callback' dir='test/parallel' n=100 ** -1.23 % ±0.90% ±1.19% ±1.53%
fs/bench-opendir.js bufferSize=1024 mode='sync' dir='lib' n=100 -0.15 % ±1.97% ±2.60% ±3.34%
fs/bench-opendir.js bufferSize=1024 mode='sync' dir='test/parallel' n=100 1.08 % ±3.17% ±4.19% ±5.38%
fs/bench-opendir.js bufferSize=32 mode='async' dir='lib' n=100 2.57 % ±2.63% ±3.47% ±4.46%
fs/bench-opendir.js bufferSize=32 mode='async' dir='test/parallel' n=100 -2.44 % ±3.00% ±3.96% ±5.09%
fs/bench-opendir.js bufferSize=32 mode='callback' dir='lib' n=100 -0.27 % ±1.62% ±2.13% ±2.74%
fs/bench-opendir.js bufferSize=32 mode='callback' dir='test/parallel' n=100 -0.79 % ±5.31% ±7.01% ±9.00%
fs/bench-opendir.js bufferSize=32 mode='sync' dir='lib' n=100 -0.25 % ±1.63% ±2.15% ±2.77%
fs/bench-opendir.js bufferSize=32 mode='sync' dir='test/parallel' n=100 0.43 % ±3.82% ±5.04% ±6.48%
fs/bench-opendir.js bufferSize=4 mode='async' dir='lib' n=100 -0.25 % ±1.46% ±1.92% ±2.47%
fs/bench-opendir.js bufferSize=4 mode='async' dir='test/parallel' n=100 * 1.08 % ±0.95% ±1.25% ±1.61%
fs/bench-opendir.js bufferSize=4 mode='callback' dir='lib' n=100 -0.23 % ±1.37% ±1.80% ±2.32%
fs/bench-opendir.js bufferSize=4 mode='callback' dir='test/parallel' n=100 0.10 % ±1.22% ±1.61% ±2.06%
fs/bench-opendir.js bufferSize=4 mode='sync' dir='lib' n=100 0.28 % ±1.79% ±2.36% ±3.03%
fs/bench-opendir.js bufferSize=4 mode='sync' dir='test/parallel' n=100 * -4.02 % ±3.35% ±4.42% ±5.69%
fs/bench-readdir.js withFileTypes='false' dir='lib' n=10 -0.43 % ±2.32% ±3.06% ±3.94%
fs/bench-readdir.js withFileTypes='false' dir='test/parallel' n=10 0.37 % ±0.65% ±0.85% ±1.10%
fs/bench-readdir.js withFileTypes='true' dir='lib' n=10 1.40 % ±2.30% ±3.03% ±3.90%
fs/bench-readdir.js withFileTypes='true' dir='test/parallel' n=10 -0.31 % ±0.55% ±0.73% ±0.94%
fs/bench-readdirSync.js withFileTypes='false' dir='lib' n=10 -1.64 % ±4.83% ±6.37% ±8.19%
fs/bench-readdirSync.js withFileTypes='false' dir='test/parallel' n=10 -0.52 % ±0.72% ±0.95% ±1.21%
fs/bench-readdirSync.js withFileTypes='true' dir='lib' n=10 1.32 % ±5.38% ±7.10% ±9.13%
fs/bench-readdirSync.js withFileTypes='true' dir='test/parallel' n=10 -0.66 % ±0.69% ±0.92% ±1.18%
fs/bench-realpath.js pathType='relative' n=10000 -1.23 % ±2.67% ±3.52% ±4.52%
fs/bench-realpath.js pathType='resolved' n=10000 0.32 % ±1.38% ±1.82% ±2.34%
fs/bench-realpathSync.js pathType='relative' n=10000 -0.60 % ±3.04% ±4.02% ±5.16%
fs/bench-realpathSync.js pathType='resolved' n=10000 -1.38 % ±2.87% ±3.79% ±4.87%
fs/bench-stat-promise.js statType='fstat' n=200000 1.02 % ±1.10% ±1.45% ±1.86%
fs/bench-stat-promise.js statType='lstat' n=200000 * 0.97 % ±0.94% ±1.24% ±1.59%
fs/bench-stat-promise.js statType='stat' n=200000 * 1.12 % ±0.88% ±1.16% ±1.49%
fs/bench-stat.js statType='fstat' n=200000 * -1.19 % ±0.98% ±1.30% ±1.67%
fs/bench-stat.js statType='lstat' n=200000 * 1.08 % ±1.03% ±1.36% ±1.75%
fs/bench-stat.js statType='stat' n=200000 -0.06 % ±1.06% ±1.40% ±1.80%
fs/bench-statSync-failure.js statSyncType='noThrow' n=1000000 -0.53 % ±0.69% ±0.91% ±1.17%
fs/bench-statSync-failure.js statSyncType='throw' n=1000000 -0.03 % ±1.02% ±1.35% ±1.73%
fs/bench-statSync.js statSyncType='fstatSync' n=1000000 0.11 % ±0.63% ±0.84% ±1.08%
fs/bench-statSync.js statSyncType='lstatSync' n=1000000 -0.25 % ±0.82% ±1.08% ±1.39%
fs/bench-statSync.js statSyncType='statSync' n=1000000 -0.41 % ±0.63% ±0.83% ±1.07%
fs/read-stream-throughput.js n=1024 highWaterMark=1024 filesize=1024000 encodingType='asc' 1.06 % ±1.39% ±1.84% ±2.37%
fs/read-stream-throughput.js n=1024 highWaterMark=1024 filesize=1024000 encodingType='buf' * 1.10 % ±0.94% ±1.24% ±1.59%
fs/read-stream-throughput.js n=1024 highWaterMark=1024 filesize=1024000 encodingType='utf' 0.38 % ±0.79% ±1.04% ±1.34%
fs/read-stream-throughput.js n=1024 highWaterMark=1048576 filesize=1024000 encodingType='asc' -0.73 % ±0.95% ±1.26% ±1.62%
fs/read-stream-throughput.js n=1024 highWaterMark=1048576 filesize=1024000 encodingType='buf' * 0.94 % ±0.74% ±0.98% ±1.25%
fs/read-stream-throughput.js n=1024 highWaterMark=1048576 filesize=1024000 encodingType='utf' 0.14 % ±0.46% ±0.60% ±0.78%
fs/read-stream-throughput.js n=1024 highWaterMark=4096 filesize=1024000 encodingType='asc' -0.13 % ±0.97% ±1.28% ±1.64%
fs/read-stream-throughput.js n=1024 highWaterMark=4096 filesize=1024000 encodingType='buf' 0.26 % ±0.89% ±1.18% ±1.51%
fs/read-stream-throughput.js n=1024 highWaterMark=4096 filesize=1024000 encodingType='utf' 0.18 % ±0.37% ±0.48% ±0.62%
fs/read-stream-throughput.js n=1024 highWaterMark=65535 filesize=1024000 encodingType='asc' -0.59 % ±1.79% ±2.36% ±3.04%
fs/read-stream-throughput.js n=1024 highWaterMark=65535 filesize=1024000 encodingType='buf' 0.54 % ±1.24% ±1.64% ±2.11%
fs/read-stream-throughput.js n=1024 highWaterMark=65535 filesize=1024000 encodingType='utf' -0.08 % ±0.36% ±0.47% ±0.61%
fs/readfile-partitioned.js concurrent=1 len=1024 encoding='' duration=5 0.04 % ±0.67% ±0.88% ±1.13%
fs/readfile-partitioned.js concurrent=1 len=1024 encoding='utf-8' duration=5 -0.04 % ±0.73% ±0.96% ±1.24%
fs/readfile-partitioned.js concurrent=1 len=16777216 encoding='' duration=5 0.04 % ±0.94% ±1.24% ±1.59%
fs/readfile-partitioned.js concurrent=1 len=16777216 encoding='utf-8' duration=5 -1.59 % ±1.78% ±2.35% ±3.01%
fs/readfile-partitioned.js concurrent=10 len=1024 encoding='' duration=5 0.03 % ±1.07% ±1.41% ±1.81%
fs/readfile-partitioned.js concurrent=10 len=1024 encoding='utf-8' duration=5 0.67 % ±1.16% ±1.53% ±1.97%
fs/readfile-partitioned.js concurrent=10 len=16777216 encoding='' duration=5 0.31 % ±1.23% ±1.62% ±2.08%
fs/readfile-partitioned.js concurrent=10 len=16777216 encoding='utf-8' duration=5 -1.21 % ±1.85% ±2.44% ±3.13%
fs/readfile-permission-enabled.js concurrent=1 len=1024 encoding='' duration=5 * -1.02 % ±0.91% ±1.20% ±1.54%
fs/readfile-permission-enabled.js concurrent=1 len=1024 encoding='utf-8' duration=5 0.54 % ±0.84% ±1.11% ±1.42%
fs/readfile-permission-enabled.js concurrent=1 len=16777216 encoding='' duration=5 1.73 % ±2.23% ±2.95% ±3.79%
fs/readfile-permission-enabled.js concurrent=1 len=16777216 encoding='utf-8' duration=5 0.04 % ±0.40% ±0.52% ±0.67%
fs/readfile-permission-enabled.js concurrent=10 len=1024 encoding='' duration=5 -0.58 % ±1.03% ±1.36% ±1.75%
fs/readfile-permission-enabled.js concurrent=10 len=1024 encoding='utf-8' duration=5 0.30 % ±1.21% ±1.60% ±2.05%
fs/readfile-permission-enabled.js concurrent=10 len=16777216 encoding='' duration=5 -0.28 % ±2.86% ±3.78% ±4.85%
fs/readfile-permission-enabled.js concurrent=10 len=16777216 encoding='utf-8' duration=5 -0.34 % ±0.84% ±1.10% ±1.42%
fs/readfile-promises.js concurrent=1 len=1024 encoding='' duration=5 * 1.43 % ±1.32% ±1.74% ±2.23%
fs/readfile-promises.js concurrent=1 len=1024 encoding='utf-8' duration=5 0.01 % ±1.40% ±1.85% ±2.38%
fs/readfile-promises.js concurrent=1 len=16777216 encoding='' duration=5 * -0.66 % ±0.64% ±0.85% ±1.09%
fs/readfile-promises.js concurrent=1 len=16777216 encoding='utf-8' duration=5 -0.23 % ±0.60% ±0.79% ±1.01%
fs/readfile-promises.js concurrent=1 len=33554432 encoding='' duration=5 0.04 % ±0.44% ±0.58% ±0.75%
fs/readfile-promises.js concurrent=1 len=33554432 encoding='utf-8' duration=5 0.27 % ±0.48% ±0.64% ±0.82%
fs/readfile-promises.js concurrent=1 len=4194304 encoding='' duration=5 0.24 % ±0.80% ±1.05% ±1.35%
fs/readfile-promises.js concurrent=1 len=4194304 encoding='utf-8' duration=5 0.29 % ±0.96% ±1.27% ±1.63%
fs/readfile-promises.js concurrent=1 len=524288 encoding='' duration=5 0.27 % ±1.63% ±2.16% ±2.77%
fs/readfile-promises.js concurrent=1 len=524288 encoding='utf-8' duration=5 0.22 % ±1.03% ±1.36% ±1.75%
fs/readfile-promises.js concurrent=1 len=8388608 encoding='' duration=5 -0.45 % ±0.62% ±0.82% ±1.05%
fs/readfile-promises.js concurrent=1 len=8388608 encoding='utf-8' duration=5 -0.09 % ±0.46% ±0.60% ±0.78%
fs/readfile-promises.js concurrent=10 len=1024 encoding='' duration=5 * 0.84 % ±0.79% ±1.04% ±1.33%
fs/readfile-promises.js concurrent=10 len=1024 encoding='utf-8' duration=5 -0.01 % ±0.86% ±1.14% ±1.46%
fs/readfile-promises.js concurrent=10 len=16777216 encoding='' duration=5 0.37 % ±1.03% ±1.36% ±1.74%
fs/readfile-promises.js concurrent=10 len=16777216 encoding='utf-8' duration=5 0.47 % ±0.71% ±0.93% ±1.20%
fs/readfile-promises.js concurrent=10 len=33554432 encoding='' duration=5 0.13 % ±0.64% ±0.84% ±1.09%
fs/readfile-promises.js concurrent=10 len=33554432 encoding='utf-8' duration=5 0.21 % ±0.42% ±0.55% ±0.71%
fs/readfile-promises.js concurrent=10 len=4194304 encoding='' duration=5 0.13 % ±1.24% ±1.63% ±2.10%
fs/readfile-promises.js concurrent=10 len=4194304 encoding='utf-8' duration=5 0.49 % ±0.80% ±1.05% ±1.35%
fs/readfile-promises.js concurrent=10 len=524288 encoding='' duration=5 -0.37 % ±1.71% ±2.26% ±2.90%
fs/readfile-promises.js concurrent=10 len=524288 encoding='utf-8' duration=5 0.08 % ±0.65% ±0.86% ±1.10%
fs/readfile-promises.js concurrent=10 len=8388608 encoding='' duration=5 0.62 % ±0.94% ±1.24% ±1.60%
fs/readfile-promises.js concurrent=10 len=8388608 encoding='utf-8' duration=5 0.48 % ±0.75% ±0.99% ±1.27%
fs/readfile.js concurrent=1 len=1024 encoding='' duration=5 * -0.76 % ±0.74% ±0.97% ±1.25%
fs/readfile.js concurrent=1 len=1024 encoding='utf-8' duration=5 0.44 % ±0.77% ±1.02% ±1.31%
fs/readfile.js concurrent=1 len=16777216 encoding='' duration=5 0.04 % ±2.56% ±3.38% ±4.35%
fs/readfile.js concurrent=1 len=16777216 encoding='utf-8' duration=5 0.06 % ±0.39% ±0.52% ±0.67%
fs/readfile.js concurrent=10 len=1024 encoding='' duration=5 0.60 % ±1.06% ±1.40% ±1.79%
fs/readfile.js concurrent=10 len=1024 encoding='utf-8' duration=5 * 1.25 % ±0.98% ±1.29% ±1.66%
fs/readfile.js concurrent=10 len=16777216 encoding='' duration=5 -1.11 % ±2.72% ±3.59% ±4.61%
fs/readfile.js concurrent=10 len=16777216 encoding='utf-8' duration=5 0.45 % ±0.89% ±1.17% ±1.50%
fs/readFileSync.js n=600 path='existing' encoding='undefined' -0.85 % ±2.33% ±3.07% ±3.95%
fs/readFileSync.js n=600 path='existing' encoding='utf8' -0.69 % ±2.34% ±3.09% ±3.97%
fs/readFileSync.js n=600 path='non-existing' encoding='undefined' -0.73 % ±1.21% ±1.60% ±2.06%
fs/readFileSync.js n=600 path='non-existing' encoding='utf8' 0.19 % ±1.39% ±1.84% ±2.36%
fs/write-stream-throughput.js size=1024 encodingType='asc' dur=5 0.39 % ±0.85% ±1.12% ±1.45%
fs/write-stream-throughput.js size=1024 encodingType='buf' dur=5 -0.10 % ±0.72% ±0.95% ±1.23%
fs/write-stream-throughput.js size=1024 encodingType='utf' dur=5 0.05 % ±0.69% ±0.91% ±1.17%
fs/write-stream-throughput.js size=1048576 encodingType='asc' dur=5 0.37 % ±0.79% ±1.04% ±1.34%
fs/write-stream-throughput.js size=1048576 encodingType='buf' dur=5 0.13 % ±0.30% ±0.39% ±0.50%
fs/write-stream-throughput.js size=1048576 encodingType='utf' dur=5 0.42 % ±0.79% ±1.04% ±1.34%
fs/write-stream-throughput.js size=2 encodingType='asc' dur=5 * 0.95 % ±0.86% ±1.13% ±1.45%
fs/write-stream-throughput.js size=2 encodingType='buf' dur=5 -0.56 % ±0.91% ±1.21% ±1.55%
fs/write-stream-throughput.js size=2 encodingType='utf' dur=5 0.41 % ±1.12% ±1.48% ±1.90%
fs/write-stream-throughput.js size=65535 encodingType='asc' dur=5 0.04 % ±0.45% ±0.59% ±0.76%
fs/write-stream-throughput.js size=65535 encodingType='buf' dur=5 -0.08 % ±0.37% ±0.48% ±0.62%
fs/write-stream-throughput.js size=65535 encodingType='utf' dur=5 -0.00 % ±1.05% ±1.38% ±1.77%
fs/writefile-promises.js concurrent=1 size=1024 encodingType='asc' duration=5 0.59 % ±1.55% ±2.04% ±2.62%
fs/writefile-promises.js concurrent=1 size=1024 encodingType='buf' duration=5 -0.14 % ±1.58% ±2.08% ±2.67%
fs/writefile-promises.js concurrent=1 size=1024 encodingType='utf' duration=5 * 1.59 % ±1.53% ±2.02% ±2.60%
fs/writefile-promises.js concurrent=1 size=1048576 encodingType='asc' duration=5 0.32 % ±0.99% ±1.31% ±1.68%
fs/writefile-promises.js concurrent=1 size=1048576 encodingType='buf' duration=5 0.20 % ±0.62% ±0.82% ±1.05%
fs/writefile-promises.js concurrent=1 size=1048576 encodingType='utf' duration=5 0.49 % ±0.78% ±1.03% ±1.33%
fs/writefile-promises.js concurrent=1 size=2 encodingType='asc' duration=5 -0.19 % ±1.53% ±2.02% ±2.59%
fs/writefile-promises.js concurrent=1 size=2 encodingType='buf' duration=5 1.01 % ±1.50% ±1.97% ±2.54%
fs/writefile-promises.js concurrent=1 size=2 encodingType='utf' duration=5 -0.37 % ±1.57% ±2.07% ±2.66%
fs/writefile-promises.js concurrent=1 size=65535 encodingType='asc' duration=5 -0.33 % ±2.07% ±2.74% ±3.52%
fs/writefile-promises.js concurrent=1 size=65535 encodingType='buf' duration=5 -0.11 % ±1.70% ±2.24% ±2.88%
fs/writefile-promises.js concurrent=1 size=65535 encodingType='utf' duration=5 -0.75 % ±1.53% ±2.02% ±2.59%
fs/writefile-promises.js concurrent=10 size=1024 encodingType='asc' duration=5 0.58 % ±1.01% ±1.33% ±1.71%
fs/writefile-promises.js concurrent=10 size=1024 encodingType='buf' duration=5 0.47 % ±0.69% ±0.92% ±1.18%
fs/writefile-promises.js concurrent=10 size=1024 encodingType='utf' duration=5 0.58 % ±1.07% ±1.41% ±1.81%
fs/writefile-promises.js concurrent=10 size=1048576 encodingType='asc' duration=5 0.17 % ±0.73% ±0.96% ±1.24%
fs/writefile-promises.js concurrent=10 size=1048576 encodingType='buf' duration=5 -0.46 % ±1.37% ±1.81% ±2.32%
fs/writefile-promises.js concurrent=10 size=1048576 encodingType='utf' duration=5 -0.14 % ±0.54% ±0.71% ±0.91%
fs/writefile-promises.js concurrent=10 size=2 encodingType='asc' duration=5 0.38 % ±0.81% ±1.06% ±1.37%
fs/writefile-promises.js concurrent=10 size=2 encodingType='buf' duration=5 -0.31 % ±0.98% ±1.30% ±1.67%
fs/writefile-promises.js concurrent=10 size=2 encodingType='utf' duration=5 0.17 % ±0.79% ±1.04% ±1.33%
fs/writefile-promises.js concurrent=10 size=65535 encodingType='asc' duration=5 -0.43 % ±1.05% ±1.39% ±1.78%
fs/writefile-promises.js concurrent=10 size=65535 encodingType='buf' duration=5 -0.33 % ±1.07% ±1.41% ±1.82%
fs/writefile-promises.js concurrent=10 size=65535 encodingType='utf' duration=5 0.39 % ±1.07% ±1.41% ±1.81%
Landed in b3ec13d4497398a8a85738a64849570462660a4f