-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
feat(fs): Make parameters optional for readSync #32460
Conversation
const defaultBuffer1 = Buffer.allocUnsafe(expected.length); | ||
const defaultBuffer2 = Buffer.allocUnsafe(expected.length); | ||
const defaultBuffer3 = Buffer.allocUnsafe(expected.length); | ||
|
||
// Test passing in an empty options object | ||
const result1 = fs.readSync(fd, defaultBuffer1, { position: 0 }); | ||
assert.strictEqual(result1, expected.length); | ||
assert.deepStrictEqual(defaultBuffer1, expected); | ||
|
||
// Test not passing in any options object | ||
const result2 = fs.readSync(fd, defaultBuffer2); | ||
assert.strictEqual(result2, expected.length); | ||
assert.deepStrictEqual(defaultBuffer2, expected); | ||
|
||
|
||
// Test passing in options | ||
const result3 = fs.readSync(fd, defaultBuffer3, { | ||
offset: 0, | ||
length: defaultBuffer3.length, | ||
position: 0 | ||
}); | ||
|
||
assert.strictEqual(result3, expected.length); | ||
assert.deepStrictEqual(defaultBuffer3, expected); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Hi @lholmquist. Do you mind updating the commit message to follow our commit guidelines? We don't use |
@mmarchini yea, no problem. I should've known that already since this isn't my first contribution :) |
No worries, it's easy to forget some details from the guideline :) |
3cb5c23
to
bc32a48
Compare
LGTM if update doc and fix the following suggested changes. optional: edit the PR title to same with the commit |
bc32a48
to
d8b91e6
Compare
@himself65 Can you take another look? |
@lholmquist Sorry it took so long to get back to you, but it seems like this conflicts with recent changes. Could you rebase this? |
@addaleax no problem. rebase commencing |
* This makes the offset, length and position parameters optional by passing in an options object.
fb855f8
to
7f68e77
Compare
CI: https://ci.nodejs.org/job/node-test-pull-request/30269/ (:heavy_check_mark:) |
This makes the offset, length and position parameters optional by passing in an options object. PR-URL: #32460 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Landed in 88b4e86 🙂 |
This makes the offset, length and position parameters optional by passing in an options object. PR-URL: #32460 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This makes the offset, length and position parameters optional by passing in an options object. PR-URL: #32460 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Notable changes: New file system APIs: * Added a new function, `fs.readv` (with sync and promisified versions). This function takes an array of `ArrayBufferView` elements and will write the data it reads sequentially to the buffers (Sk Sajidul Kadir). #32356 * A new overload is available for `fs.readSync`, which allows to optionally pass any of the `offset`, `length` and `position` parameters. #32460 Other changes: * dns: * Added the `dns.ALL` flag, that can be passed to `dns.lookup()` with `dns.V4MAPPED` to return resolved IPv6 addresses as well as IPv4 mapped IPv6 addresses (murgatroid99). #32183 * http: * The default maximum HTTP header size was changed from 8KB to 16KB (rosaxny). #32520 * n-api: * Calls to `napi_call_threadsafe_function` from the main thread can now return the `napi_would_deadlock` status in certain circumstances (Gabriel Schulhof). #32689 * util: * Added a new `maxStrLength` option to `util.inspect`, to control the maximum length of printed strings. Its default value is `Infinity` (rosaxny). #32392 * worker: * Added support for passing a `transferList` along with `workerData` to the `Worker` constructor (Juan José Arboleda). #32278 New core collaborators: With this release, we welcome three new Node.js core collaborators: * himself65. #32734 * flarna (Gerhard Stoebich). #32620 * mildsunrise (Alba Mendez). #32525 PR-URL: #32813
Notable changes: New file system APIs: * Added a new function, `fs.readv` (with sync and promisified versions). This function takes an array of `ArrayBufferView` elements and will write the data it reads sequentially to the buffers (Sk Sajidul Kadir). #32356 * A new overload is available for `fs.readSync`, which allows to optionally pass any of the `offset`, `length` and `position` parameters. #32460 Other changes: * dns: * Added the `dns.ALL` flag, that can be passed to `dns.lookup()` with `dns.V4MAPPED` to return resolved IPv6 addresses as well as IPv4 mapped IPv6 addresses (murgatroid99). #32183 * http: * The default maximum HTTP header size was changed from 8KB to 16KB (rosaxny). #32520 * n-api: * Calls to `napi_call_threadsafe_function` from the main thread can now return the `napi_would_deadlock` status in certain circumstances (Gabriel Schulhof). #32689 * util: * Added a new `maxStrLength` option to `util.inspect`, to control the maximum length of printed strings. Its default value is `Infinity` (rosaxny). #32392 * worker: * Added support for passing a `transferList` along with `workerData` to the `Worker` constructor (Juan José Arboleda). #32278 New core collaborators: With this release, we welcome three new Node.js core collaborators: * himself65. #32734 * flarna (Gerhard Stoebich). #32620 * mildsunrise (Alba Mendez). #32525 PR-URL: #32813
Notable changes: New file system APIs: * Added a new function, `fs.readv` (with sync and promisified versions). This function takes an array of `ArrayBufferView` elements and will write the data it reads sequentially to the buffers (Sk Sajidul Kadir). #32356 * A new overload is available for `fs.readSync`, which allows to optionally pass any of the `offset`, `length` and `position` parameters. #32460 Other changes: * dns: * Added the `dns.ALL` flag, that can be passed to `dns.lookup()` with `dns.V4MAPPED` to return resolved IPv6 addresses as well as IPv4 mapped IPv6 addresses (murgatroid99). #32183 * http: * The default maximum HTTP header size was changed from 8KB to 16KB (rosaxny). #32520 * n-api: * Calls to `napi_call_threadsafe_function` from the main thread can now return the `napi_would_deadlock` status in certain circumstances (Gabriel Schulhof). #32689 * util: * Added a new `maxStrLength` option to `util.inspect`, to control the maximum length of printed strings. Its default value is `Infinity` (rosaxny). #32392 * worker: * Added support for passing a `transferList` along with `workerData` to the `Worker` constructor (Juan José Arboleda). #32278 New core collaborators: With this release, we welcome three new Node.js core collaborators: * himself65. #32734 * flarna (Gerhard Stoebich). #32620 * mildsunrise (Alba Mendez). #32525 PR-URL: #32813
This makes the offset, length and position parameters optional by passing in an options object. PR-URL: nodejs#32460 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This makes the offset, length and position parameters optional by passing in an options object. PR-URL: #32460 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesSimilar to the recently merged #31402, which was for fs.read, this PR does something similar for fs.readSync
This adds the signature
fs.readSync(fd, buffer, options)
, where the options is an object that can contain optional values for offset, length and position.The difference with this PR and the previous one for fs.read, is that here i'm making the buffer object not optional. Since the function returns the amount of bytes read, the user needs to use the buffer they pass in to actually read value of what they are trying to read.
I still need to add docs for this, but wanted to get any thoughts on if also making buffer optional and part of the options object which would then change the new function signature to
fs.readSync(fd, {})