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: promises have undocumented write(string,…) method #20406

Closed
ChALkeR opened this issue Apr 29, 2018 · 16 comments
Closed

fs: promises have undocumented write(string,…) method #20406

ChALkeR opened this issue Apr 29, 2018 · 16 comments
Labels
doc Issues and PRs related to the documentations. experimental Issues and PRs related to experimental features. fs Issues and PRs related to the fs subsystem / file system. good first issue Issues that are suitable for first-time contributors. promises Issues and PRs related to ECMAScript promises.

Comments

@ChALkeR
Copy link
Member

ChALkeR commented Apr 29, 2018

  • Version: 10.0.0, master
  • Subsystem: fs

Non-promises API has two variants documented: Buffer, string.

Promises API has only Buffer variants documented: method, class method.

This code works, but it's undocumented behavior:

const fs = require('fs/promises');
const fd = await fs.open('temp.txt', 'w+');
fd.write('test\n');
@ChALkeR ChALkeR added the fs Issues and PRs related to the fs subsystem / file system. label Apr 29, 2018
@ChALkeR
Copy link
Member Author

ChALkeR commented Apr 29, 2018

Not sure if this is a documentation issue. Should we keep that API in such form?

@BridgeAR
Copy link
Member

Without looking into it further: as far as I know the promises API should be identical to the non-promise one besides returning promises. So it sounds like a documentation issue.

@ChALkeR ChALkeR added the doc Issues and PRs related to the documentations. label Apr 29, 2018
@ChALkeR ChALkeR mentioned this issue Apr 29, 2018
4 tasks
@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 29, 2018

Refs: #18297 (comment) and next comment:

Yes, the omission of the fs.write(fd, string, position, encoding, callback) variant is intentional.

so cc @jasnell

@vsemozhetbyt vsemozhetbyt added the promises Issues and PRs related to ECMAScript promises. label Apr 29, 2018
@ChALkeR
Copy link
Member Author

ChALkeR commented Apr 29, 2018

It's undocumented, but present and partially broken — see #20407.

@ChALkeR
Copy link
Member Author

ChALkeR commented Apr 30, 2018

Note that according to coverage report, that variant is called once, which means that there is a test that depends on it being present.

@jasnell
Copy link
Member

jasnell commented Apr 30, 2018

Doc omission. The variant should be doc'd.

@jasnell
Copy link
Member

jasnell commented Apr 30, 2018

It was a to-do that I never went back to. Although if I recall correctly there may need to be some reconcilation still with the non-promise version

@jasnell
Copy link
Member

jasnell commented Apr 30, 2018

@BridgeAR ... To be certain the promise certain is not identical. There are intended differences... Such as the use of the FileHandle object rather than numeric fd.

@BridgeAR
Copy link
Member

BridgeAR commented Apr 30, 2018

That does not sound intuitive to me at all. I would have expected it is fine to switch to promises 1-to-1. Can you outline the specific differences / where there a lot of these?

@ChALkeR ChALkeR added the experimental Issues and PRs related to experimental features. label May 8, 2018
@ChALkeR
Copy link
Member Author

ChALkeR commented May 8, 2018

@BridgeAR The ones I noticed:

  1. callbacks → promises
  2. fd → filehandle
  3. constants not there (fs.constants, fs.*_OK),
  4. classes not there (fs.Stats, fs.WriteStream, etc.),
  5. some methods are not there, see fs/promises API inconsitency (.close not there) #20548close, *Stream, *watch*, *Sync, exists. fs: drop duplicate API in promises mode #20559 should remove even more.
  6. return values is different

Example:

> await (await fsp.open('test.txt', 'w')).write('test')
{ bytesWritten: 4, buffer: 'test' }
> fs.writeSync(fs.openSync('test.txt', 'w'), 'test')
4

@BridgeAR
Copy link
Member

BridgeAR commented May 8, 2018

@ChALkeR thanks for pointing these things out.

@ChALkeR
Copy link
Member Author

ChALkeR commented May 8, 2018

@BridgeAR I actually think that we could merge fs.promises into fs, after removing all fd-using methods from fs.promises. It shouldn't be that hard, though different return values might confuse people a bit, but I don't expect that to be a large problem with proper documentation.

@jasnell
Copy link
Member

jasnell commented May 8, 2018

Big -1 on merging the APIs. Polymorphic returns are awful and it's not something we can do consistently across the core API. fs.promises should remain a separate API path.

@tjcrowder
Copy link

@jasnell - Currently, the implementation of filehandle.write doesn't accept an (optional) encoding parameter, so is this a documentation-only issue or does it need the param (and the attendant shuffling around of params)? FWIW, since this is a new API, my complete-outsider view would be don't bother with an encoding parameter, just say (and ensure) that if you provide a string, UTF-8 will be used, and if you want something else provide a buffer instead. :-) (I'm happy to take this issue and do a PR if it's doc-only, or perhaps even if adding the param is required if I can ping you with the occasional question as I ramp up.)

@ChALkeR
Copy link
Member Author

ChALkeR commented Jul 9, 2018

@nodejs/collaborators 👍 for good-first-issue (doc omission for .write(string).

@ChALkeR ChALkeR added the good first issue Issues that are suitable for first-time contributors. label Jul 11, 2018
@darahayes
Copy link

@ChALkeR @jasnell Hey folks, I just submitted a docs PR for this issue. I hope it helps in some way. I've raised some questions in there. Cheers!

darahayes pushed a commit to darahayes/node that referenced this issue Nov 13, 2018
Add missing docs for filehandle.write(string[, position[, encoding]])
In the fs.promises API.

fixes: nodejs#20406
@Trott Trott closed this as completed in 692b09f Nov 20, 2018
targos pushed a commit that referenced this issue Nov 20, 2018
Add missing docs for filehandle.write(string[, position[, encoding]])
In the fs.promises API.

Fixes: #20406
PR-URL: #23224
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
rvagg pushed a commit that referenced this issue Nov 28, 2018
Add missing docs for filehandle.write(string[, position[, encoding]])
In the fs.promises API.

Fixes: #20406
PR-URL: #23224
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
codebytere pushed a commit that referenced this issue Jan 13, 2019
Add missing docs for filehandle.write(string[, position[, encoding]])
In the fs.promises API.

Fixes: #20406
PR-URL: #23224
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
refack pushed a commit to refack/node that referenced this issue Jan 14, 2019
Add missing docs for filehandle.write(string[, position[, encoding]])
In the fs.promises API.

Fixes: nodejs#20406
PR-URL: nodejs#23224
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
codebytere pushed a commit that referenced this issue Jan 29, 2019
Add missing docs for filehandle.write(string[, position[, encoding]])
In the fs.promises API.

Fixes: #20406
PR-URL: #23224
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. experimental Issues and PRs related to experimental features. fs Issues and PRs related to the fs subsystem / file system. good first issue Issues that are suitable for first-time contributors. promises Issues and PRs related to ECMAScript promises.
Projects
None yet
Development

No branches or pull requests

6 participants