Skip to content

fs: fix `createReadStream(…, {end: n})` for non-seekable fds

Rodrigo Muino Tomonari requested to merge github/fork/addaleax/19240 into master

82bdf8fb fixed an issue by silently modifying the start option for the case when only end is passed, in order to perform reads from a specified range in the file.

However, that approach does not work for non-seekable files, since a numeric start option means that positioned reads will be used to read data from the file.

This patch fixes that, and instead ends reading after a specified size by adjusting the read buffer size.

This way we avoid re-introducing the bug that 82bdf8fb fixed, and align behaviour with the native file stream mechanism introduced in https://github.com/nodejs/node/pull/18936 as well.

Fixes: https://github.com/nodejs/node/issues/19240 Refs: https://github.com/nodejs/node/pull/18121

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Merge request reports

Loading