-
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
doc: clarify fd behaviour with {read,write}File #23706
Changes from 1 commit
351d9df
5370c14
b5a440c
d44bf9f
121e1dd
9975e9a
ef290a7
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 | ||||
---|---|---|---|---|---|---|
|
@@ -2547,10 +2547,13 @@ fs.readFile('<directory>', (err, data) => { | |||||
}); | ||||||
``` | ||||||
|
||||||
Any specified file descriptor has to support reading. | ||||||
|
||||||
If a file descriptor is specified as the `path`, it will not be closed | ||||||
### File Descriptors | ||||||
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 | ||||||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Suggested change
|
||||||
|
||||||
The `fs.readFile()` function buffers the entire file. To minimize memory costs, | ||||||
when possible prefer streaming via `fs.createReadStream()`. | ||||||
|
@@ -3540,14 +3543,21 @@ If `options` is a string, then it specifies the encoding: | |||||
fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback); | ||||||
``` | ||||||
|
||||||
Any specified file descriptor has to support writing. | ||||||
### File Descriptors | ||||||
1. Any specified file descriptor has to support writing. | ||||||
2. If a file descriptor is specified as the `file`, it will not be closed | ||||||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a bit confusing as
Suggested change
|
||||||
For example, if the file already had `'Hello World'` and the newly written | ||||||
content is `'Aloha'`, then the contents of the file would be `'Aloha World'`, | ||||||
rather than just `'Aloha'`. | ||||||
|
||||||
It is unsafe to use `fs.writeFile()` multiple times on the same file without | ||||||
waiting for the callback. For this scenario, [`fs.createWriteStream()`][] is | ||||||
recommended. | ||||||
|
||||||
If a file descriptor is specified as the `file`, it will not be closed | ||||||
automatically. | ||||||
|
||||||
## fs.writeFileSync(file, data[, options]) | ||||||
<!-- YAML | ||||||
|
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.
Clarify that the
If ...
is an example?Something like
E.g., if ...
orFor example, if ...
.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.
Ack.