-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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: improve argument handling for ReadStream #19898
Closed
Closed
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e507f93
fs: improve argument handling for ReadStream
ryzokuken 30c285f
test,fs: update tests for improvements in ReadStream
ryzokuken 915d77c
Remove inconsistency
ryzokuken 17d6d55
Separate testing for start and end
ryzokuken 36574f4
Remove invalid check
ryzokuken e4415d5
Address comments regarding handling undefined
ryzokuken b946616
Refactor conditions
ryzokuken d00b46a
fs,doc: add documentation regarding changes to createReadStream
ryzokuken 93b0915
Add a changes block and move new documentation towards the end
ryzokuken 5d03199
Replace version by REPLACEME
ryzokuken 047529b
Minimize comments and documentation
ryzokuken a90457b
Address nit by adding parens
ryzokuken c3be59a
Resolve merge conflict
ryzokuken 41b3a2e
Thow RangeError on fractional values
ryzokuken 3530baa
Cleanup fs.md
ryzokuken 4863dba
Fix error
ryzokuken 1cf1814
Fix failures
ryzokuken 2c35628
Address nit
ryzokuken a24f115
Use isSafeInteger over isInteger
ryzokuken 0368397
Change error message
ryzokuken b6fa515
Improve error handling
ryzokuken 7bda63c
Refactor fs tests for brevity
ryzokuken c34ba43
Address nits
ryzokuken 30e36c2
Update RangeError error message
ryzokuken 9af225c
Update RangeError error message v2
ryzokuken c76e75a
Fix lint errors
ryzokuken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2014,30 +2014,40 @@ function ReadStream(path, options) { | |
this.closed = false; | ||
|
||
if (this.start !== undefined) { | ||
if (typeof this.start !== 'number' || Number.isNaN(this.start)) { | ||
throw new ERR_INVALID_ARG_TYPE('start', 'number', this.start); | ||
} | ||
if (this.end === undefined) { | ||
this.end = Infinity; | ||
} else if (typeof this.end !== 'number' || Number.isNaN(this.end)) { | ||
throw new ERR_INVALID_ARG_TYPE('end', 'number', this.end); | ||
if (!Number.isSafeInteger(this.start)) { | ||
if (typeof this.start !== 'number') | ||
throw new ERR_INVALID_ARG_TYPE('start', 'number', this.start); | ||
if (!Number.isInteger(this.start)) | ||
throw new ERR_OUT_OF_RANGE('start', 'an integer', this.start); | ||
throw new ERR_OUT_OF_RANGE('start', '=> 0 and <= 2 ** 53 - 1', this.start); | ||
} | ||
|
||
if (this.start > this.end) { | ||
const errVal = `{start: ${this.start}, end: ${this.end}}`; | ||
throw new ERR_OUT_OF_RANGE('start', '<= "end"', errVal); | ||
if (this.start < 0) { | ||
throw new ERR_OUT_OF_RANGE('start', '=> 0 and <= 2 ** 53 - 1', this.start); | ||
} | ||
|
||
this.pos = this.start; | ||
} | ||
|
||
// Backwards compatibility: Make sure `end` is a number regardless of `start`. | ||
// TODO(addaleax): Make the above typecheck not depend on `start` instead. | ||
// (That is a semver-major change). | ||
if (typeof this.end !== 'number') | ||
if (this.end === undefined) { | ||
this.end = Infinity; | ||
else if (Number.isNaN(this.end)) | ||
throw new ERR_INVALID_ARG_TYPE('end', 'number', this.end); | ||
} else if (this.end !== Infinity) { | ||
if (!Number.isSafeInteger(this.end)) { | ||
if (typeof this.end !== 'number') | ||
throw new ERR_INVALID_ARG_TYPE('end', 'number', this.end); | ||
if (!Number.isInteger(this.end)) | ||
throw new ERR_OUT_OF_RANGE('end', 'an integer', this.end); | ||
throw new ERR_OUT_OF_RANGE('end', '>= 0 and <= 2 ** 53 - 1', this.end); | ||
} | ||
|
||
if (this.end < 0) { | ||
throw new ERR_OUT_OF_RANGE('end', '>= 0 and <= 2 ** 53 - 1', this.end); | ||
} | ||
|
||
if (this.start !== undefined && this.start > this.end) { | ||
const errVal = `{start: ${this.start}, end: ${this.end}}`; | ||
throw new ERR_OUT_OF_RANGE('start', `<= "end" (here: ${this.end})`, errVal); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should now be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll remove the |
||
} | ||
} | ||
|
||
if (typeof this.fd !== 'number') | ||
this.open(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You were right about changing => to >= below but that should also be done here :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I'm sorry to have missed that out, changing ASAP.