-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
doc: add description for filehandle.write(string[, position[, encoding]]) #23224
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -3939,6 +3939,37 @@ On Linux, positional writes do not work when the file is opened in append mode. | |
| The kernel ignores the position argument and always appends the data to | ||
| the end of the file. | ||
|
|
||
| #### filehandle.write(string[, position[, encoding]]) | ||
| <!-- YAML | ||
| added: v10.0.0 | ||
| --> | ||
|
|
||
| * `string` {string} | ||
| * `position` {integer} | ||
| * `encoding` {string} **Default:** `'utf8'` | ||
| * Returns: {Promise} | ||
|
|
||
| Write `string` to the file. If `string` is not a string, then | ||
| the value will be coerced to one. | ||
|
|
||
| The `Promise` is resolved with an object containing a `bytesWritten` property | ||
| identifying the number of bytes written, and a `buffer` property containing | ||
| a reference to the `string` written. | ||
|
|
||
| `position` refers to the offset from the beginning of the file where this data | ||
| should be written. If the type of `position` is not a `number` the data | ||
| will be written at the current position. See pwrite(2). | ||
|
|
||
| `encoding` is the expected string encoding. | ||
|
|
||
| It is unsafe to use `filehandle.write()` multiple times on the same file | ||
| without waiting for the `Promise` to be resolved (or rejected). For this | ||
|
Member
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: a rejected promise is still resolved (and so is a promise following another promise) -
Author
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. Hey there, I've addressed some other feedback but I haven't addressed this one yet. I did that for two reasons.
All that being said: I am happy to make the suggested changes here, as well as in the other parts of the same doc to ensure consistency. |
||
| scenario, [`fs.createWriteStream()`][] is strongly recommended. | ||
|
|
||
| On Linux, positional writes do not work when the file is opened in append mode. | ||
| The kernel ignores the position argument and always appends the data to | ||
| the end of the file. | ||
|
|
||
| #### filehandle.writeFile(data, options) | ||
| <!-- YAML | ||
| added: v10.0.0 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.