Uh oh!
There was an error while loading. Please reload this page.
doc: improve fs.truncate functions' documentation - #7648
Conversation
e35369e to
f0f04e5Comparethefourtheye
commented
Jul 10, 2016
There was a problem hiding this comment.
From ftruncate(2):
The
truncate()andftruncate()functions cause the regular file named bypathor referenced byfdto be truncated to a size of preciselylengthbytes.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.
I don't know how to write this better. Suggestions?
There was a problem hiding this comment.
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').
jasnell
commented
Aug 8, 2016
LGTM with a couple of nits. |
addaleax
commented
Aug 8, 2016
@thefourtheye feel free to do with my suggestion whatever you prefer, this LGTM either way! |
6d3375c to
a005cc0CompareIf 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
7c20ba9Comparethefourtheye
commented
Aug 27, 2016
| For example, the following program retains only the first four bytes of the file | ||
| ```js | ||
| console.log(fs.readFileSync('temp.txt', 'utf8'); |
addaleax
commented
Aug 27, 2016
Left a few comments, this still LGTM! :) |
thefourtheye
commented
Aug 27, 2016
Thanks for pointing them out @addaleax. I fixed them, except the over-truncation (couldn't think of anything better :() |
addaleax
commented
Aug 27, 2016
Thanks! As far as I am concerned this seems good to go. |
addaleax
commented
Aug 27, 2016
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/ |
jasnell
commented
Aug 27, 2016
LGTM! |
Checklist
Affected core subsystem(s)
doc, fs
Description of change
The default value of the
lenparameter is zero and it is included inthe documentation.
This patch also has an example of how
ftruncatecan be used.@nodejs/fs @nodejs/documentation