-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: make read parameters optional #31237
Comments
Good first issue? |
@ronag I'd be willing to help out on this one. Just might need a little guidance to get started :) |
I've played around with this a little and i think Link to my first pass commit: lholmquist@a012cdb In my first round of testing, i create the function signature like this:
If i run this with an example like
I'll get an error because at the moment, the callback is going into the buffer value. It seems like the implementation might be simplier and less error prone if the only optional values were offset, length and position. I'm going to give that a try |
You can't use default parameters here since the last parameter is not optional. Instead you might have to do something like: read(...args) {
const callback = args.pop();
const [ buffer = Buffer.alloc(16384), offset = 0, length = buffer.length, position = null ] = args;
} Will need to check the performance implications as well. |
I have something working here: b139697 still using the default params(except for the callback). It is doing a little more typeof checking than i think is needed I'll give the spread stuff a shot and see how that goes |
i'm not a performance expert, so i don't if this is an issue, but it seem like creating that an extra default buffer if we didn't need to might affect something? Maybe not making buffer optional might be a good thing? 🤷♂️ I'll send a PR in the next day or so for more discussion Thanks @ronag for the help |
It would only be created if no buffer is provided. Default parameters are evaluated lazylily as far as I know. Might be worth to confirm though. |
👍 |
This makes all the parameters of the `fs.read` function, except for `fd` and the callback(when not using as a promise) optional. They will default to sensible defaults fixes nodejs#31237
This makes all the parameters of the `fs.read` function, except for `fd` and the callback(when not using as a promise) optional. They will default to sensible defaults. Fixes: nodejs#31237 PR-URL: nodejs#31402 Reviewed-By: Robert Nagy <ronagy@icloud.com>
At least in the promisifed version the parameters after
fd
should be optional, i.e:The non promisified is a bitter more tricky but should be doable as well.
The text was updated successfully, but these errors were encountered: