Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: fix options.end of fs.ReadStream() #18121

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,8 @@ function ReadStream(path, options) {
this.flags = options.flags === undefined ? 'r' : options.flags;
this.mode = options.mode === undefined ? 0o666 : options.mode;

this.start = options.start;
this.start = typeof this.fd !== 'number' && options.start === undefined ?
0 : options.start;
this.end = options.end;
this.autoClose = options.autoClose === undefined ? true : options.autoClose;
this.pos = undefined;
Expand Down
15 changes: 14 additions & 1 deletion test/sequential/test-stream2-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');

Expand Down Expand Up @@ -68,3 +68,16 @@ w.on('results', function(res) {
});

r.pipe(w);

{
// Verify that end works when start is not specified.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file here is named test-stream2-fs and it's in sequential. I think the test case added here belongs to test/parallel/test-fs-read-stream.js since it's more of a fs test, not a stream2 test. (Also I think this file can be moved to parallel? Although that should be done in another PR).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I just moved the new test case to test/parallel/test-fs-read-stream.js.

const end = 3;
const r = new FSReadable(file, { end });
const w = new TestWriter();

w.on('results', common.mustCall((res) => {
assert.strictEqual(w.length, end + 1);
}));

r.pipe(w);
}