doc: clarify fd behaviour with {read,write}File#23706
doc: clarify fd behaviour with {read,write}File#23706thefourtheye wants to merge 7 commits intonodejs:masterfrom
Conversation
vsemozhetbyt
left a comment
There was a problem hiding this comment.
With nit suggestions.
doc/api/fs.md
Outdated
| automatically. | ||
| 3. The reading will begin at the current position. If the file size is | ||
| 10 bytes and if six bytes are already read with this file descriptor, then | ||
| `readFile` will return only the rest of the four bytes. |
There was a problem hiding this comment.
Nit:
| `readFile` will return only the rest of the four bytes. | |
| `readFile()` will return only the rest of the four bytes. |
doc/api/fs.md
Outdated
| automatically. | ||
| 3. The writing will begin at the beginning of the file. If the file size | ||
| is 10 bytes and if six bytes are written with this file descriptor, then | ||
| `writeFile` will return six bytes newly written and four bytes from the file. |
There was a problem hiding this comment.
This seems a bit confusing as writeFileSync() returns undefined and writeFile() transfers only error to the calback. Maybe something like this this?
| `writeFile` will return six bytes newly written and four bytes from the file. | |
| the file contents would be six bytes newly written and four bytes from the file. |
|
Should we also update |
|
@vsemozhetbyt If #23709 lands, behavior of writeFile has to be updated here. |
|
Now that #23709 is gearing up to land, I want this PR also to be landed along with that. So, I have made changes to the |
doc/api/fs.md
Outdated
| 3. The writing will begin at the current position. Basically, if there are | ||
| multiple write calls to a file descriptor and then a `writeFile()` call is | ||
| made with the same file descriptor, the data would have been appended. | ||
| For example, if we did something like this |
There was a problem hiding this comment.
Maybe this line can be omitted as self-evident.
|
I am in doubt for these fragments of write counterparts:
This may be true only if the current position is the end of the file or the newly written data is less then the old rewritten data. Say, we have |
|
@vsemozhetbyt Once #23709 lands, the behaviour will become like this ➜ node git:(fix-fs-writeFile-with-fd) echo "Hello World" > /tmp/test
➜ node git:(fix-fs-writeFile-with-fd) cat ~/Desktop/Scratch/Test.js'use strict';
const fs = require('fs');
const fileName = '/tmp/test';
const fd = fs.openSync(fileName, 'w');
fs.writeFile(fd, 'Hello', function(err) {
if (err) {
throw err;
}
fs.writeFile(fd, 'World', function(err) {
if (err) {
throw err;
}
console.log(fs.readFileSync(fileName).toString());
});
});➜ node git:(fix-fs-writeFile-with-fd) ./node ~/Desktop/Scratch/Test.js
HelloWorld
➜ node git:(fix-fs-writeFile-with-fd)Even if the file has contents, the first write will always truncate the file. So, it will always seem like appending only. |
doc/api/fs.md
Outdated
| 1. Any specified file descriptor has to support reading. | ||
| 2. If a file descriptor is specified as the `path`, it will not be closed | ||
| automatically. | ||
| 3. The reading will begin at the current position. If the file size is |
There was a problem hiding this comment.
Clarify that the If ... is an example?
Something like E.g., if ... or For example, if ....
doc/api/fs.md
Outdated
|
|
||
| The `FileHandle` has to support reading. | ||
|
|
||
| **Note:** If one or more `filehandle.read()` calls are made on a file handle |
There was a problem hiding this comment.
We deliberately don't use **Note:** anymore afaik?
See #18592.
There was a problem hiding this comment.
It's not official, but there has definitely been an effort to use it much less. In this case, I think It can be dropped and you can just say what you have to say:
If one or more `filehandle.read()` calls are made on a file handleThere was a problem hiding this comment.
Makes sense. I removed the Note now.
doc/api/fs.md
Outdated
| It is unsafe to use `filehandle.writeFile()` multiple times on the same file | ||
| without waiting for the `Promise` to be resolved (or rejected). | ||
|
|
||
| **Note:** If one or more `filehandle.write()` calls are made on a file handle |
mhdawson
left a comment
There was a problem hiding this comment.
LGTM once comments are addressed.
This reverts commit b5a440c.
|
I reverted the changes necessary for #23709 and addressed the review comments. Reviewers, PTAL again. |
|
I'll land this by 31 October 2018, 07:30:00 (UTC time), if there are no objections or suggestions. |
|
Landed in 8bd6df8. |
PR-URL: #23706 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: #23706 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: #23706 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: #23706 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: #23706 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Checklist
Ref: #23433 (comment)
cc @nodejs/fs @nodejs/documentation @Trott