-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
fs: change default value of position in read and readSync #37101
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
Changes from all commits
446bdb6
44dfe5d
42a31d1
9342709
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -512,7 +512,7 @@ function openSync(path, flags, mode) { | |
| // fs.read(fd, buffer, offset, length, position, callback); | ||
| // OR | ||
| // fs.read(fd, {}, callback) | ||
| function read(fd, buffer, offset, length, position, callback) { | ||
| function read(fd, buffer, offset, length, position = -1, callback) { | ||
| fd = getValidatedFd(fd); | ||
|
|
||
| if (arguments.length <= 3) { | ||
|
|
@@ -534,7 +534,7 @@ function read(fd, buffer, offset, length, position, callback) { | |
| buffer = Buffer.alloc(16384), | ||
| offset = 0, | ||
| length = buffer.length, | ||
| position | ||
| position = -1, | ||
| } = options); | ||
| } | ||
|
|
||
|
|
@@ -562,8 +562,13 @@ function read(fd, buffer, offset, length, position, callback) { | |
|
|
||
| validateOffsetLengthRead(offset, length, buffer.byteLength); | ||
|
|
||
| if (position == null) | ||
| if (position === null) { | ||
| process.emitWarning( | ||
| `The provided ${position} is not a valid position, and is supported ` + | ||
| 'in the fs module solely for compatibility.', | ||
| 'DeprecationWarning', 'DEP01149'); | ||
| position = -1; | ||
| } | ||
|
|
||
| validatePosition(position, 'position'); | ||
|
|
||
|
|
@@ -585,14 +590,18 @@ ObjectDefineProperty(read, internalUtil.customPromisifyArgs, | |
| // fs.readSync(fd, buffer, offset, length, position); | ||
| // OR | ||
| // fs.readSync(fd, buffer, {}) or fs.readSync(fd, buffer) | ||
| function readSync(fd, buffer, offset, length, position) { | ||
| function readSync(fd, buffer, offset, length, position = -1) { | ||
| fd = getValidatedFd(fd); | ||
|
|
||
| if (arguments.length <= 3) { | ||
| // Assume fs.read(fd, buffer, options) | ||
| const options = offset || {}; | ||
|
|
||
| ({ offset = 0, length = buffer.length, position } = options); | ||
| ({ | ||
| offset = 0, | ||
| length = buffer.length, | ||
| position = -1, | ||
| } = options); | ||
| } | ||
|
|
||
| validateBuffer(buffer); | ||
|
|
@@ -616,8 +625,13 @@ function readSync(fd, buffer, offset, length, position) { | |
|
|
||
| validateOffsetLengthRead(offset, length, buffer.byteLength); | ||
|
|
||
| if (position == null) | ||
| if (position === null) { | ||
| process.emitWarning( | ||
| `The provided ${position} is not a valid position, and is supported ` + | ||
| 'in the fs module solely for compatibility.', | ||
| 'DeprecationWarning', 'DEP0149'); | ||
| position = -1; | ||
|
Member
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. Likewise here, this check should be kept |
||
| } | ||
|
|
||
| validatePosition(position, 'position'); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,7 +79,7 @@ function tempFdSync(callback) { | |
| const buf = Buffer.alloc(5); | ||
|
|
||
| // Read only five bytes, so that the position moves to five. | ||
| fs.read(fd, buf, 0, 5, null, common.mustSucceed((bytes) => { | ||
| fs.read(fd, buf, 0, 5, -1, common.mustSucceed((bytes) => { | ||
|
Contributor
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. Can you keep the EDIT: I've added the
Member
Author
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 think this should be
Contributor
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. On a second thought, we should probably deprecate it before removing it.
Member
Author
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 added the deprecation warning, test and mentioned the PR link in the YAML. PTAL. 👀 |
||
| assert.strictEqual(bytes, 5); | ||
| assert.deepStrictEqual(buf.toString(), 'Hello'); | ||
|
|
||
|
|
||
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.
We should actually keep this with
if (position === null)given that the default assignment will not work whenpositionis explicitly passed asnull.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.
@jasnell Note this was intentional, see #37101 (comment) above.
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.
@jasnell added the check back in along with a deprecation warning.