-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: improve fs.truncate functions' documentation #7648
Conversation
e35369e
to
f0f04e5
Compare
* `callback` {Function} | ||
|
||
Asynchronous ftruncate(2). No arguments other than a possible exception are | ||
given to the completion callback. | ||
|
||
If the file referred by the file descriptor has more number of bytes than the | ||
`len` then, only the first `len` bytes will be retained in the file. |
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.
From ftruncate(2)
:
The
truncate()
andftruncate()
functions cause the regular file named bypath
or referenced byfd
to be truncated to a size of preciselylength
bytes.If the file previously was larger than this size, the extra data is lost. If the file previously was shorter, it is extended, and the extended part reads as null bytes (
'\0'
).
I think something along these lines might be nice?
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.
I don't know how to write this better. Suggestions?
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.
If the file referred to by the file descriptor was larger than `len` bytes, only the first `len` bytes will be retained in the file.
How about that (it’s only a minor difference to what you wrote)?
The second paragraph below could probably be written quite closely to the man page, e.g.
If the file previously was shorter than `len` bytes, it is extended, and the extended part reads as null bytes ('\0').
LGTM with a couple of nits. |
@thefourtheye feel free to do with my suggestion whatever you prefer, this LGTM either way! |
6d3375c
to
a005cc0
Compare
If the file is over truncated, then the rest of the file should be filled with zeroes. These tests ensure the same.
The default value of the `len` parameter is zero and it is included in the documenetation. This patch also has examples of how `ftruncate` can be used.
a005cc0
to
7c20ba9
Compare
For example, the following program retains only the first four bytes of the file | ||
|
||
```js | ||
console.log(fs.readFileSync('temp.txt', 'utf8'); |
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.
typo: missing )
Left a few comments, this still LGTM! :) |
Thanks for pointing them out @addaleax. I fixed them, except the over-truncation (couldn't think of anything better :() |
Thanks! As far as I am concerned this seems good to go. |
I don’t expect any surprises, but new CI because the last one is a 404 by now: https://ci.nodejs.org/job/node-test-commit/4795/ |
LGTM! |
If the file is over truncated, then the rest of the file should be filled with null bytes. These tests ensure the same. PR-URL: #7648 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
The default value of the `len` parameter is zero and it is included in the documenetation. This patch also has examples of how `ftruncate` can be used. PR-URL: #7648 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
If the file is over truncated, then the rest of the file should be filled with null bytes. These tests ensure the same. PR-URL: nodejs#7648 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
The default value of the `len` parameter is zero and it is included in the documenetation. This patch also has examples of how `ftruncate` can be used. PR-URL: nodejs#7648 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
If the file is over truncated, then the rest of the file should be filled with null bytes. These tests ensure the same. PR-URL: #7648 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
The default value of the `len` parameter is zero and it is included in the documenetation. This patch also has examples of how `ftruncate` can be used. PR-URL: #7648 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
this is not landing cleanly on v4.x. Please feel free to manually backport |
Checklist
Affected core subsystem(s)
doc, fs
Description of change
The default value of the
len
parameter is zero and it is included inthe documentation.
This patch also has an example of how
ftruncate
can be used.@nodejs/fs @nodejs/documentation