Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

thefourtheye
Copy link
Contributor

@thefourtheye thefourtheye commented Jul 10, 2016

Checklist
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

doc, fs

Description of change

The default value of the len parameter is zero and it is included in
the documentation.

This patch also has an example of how ftruncate can be used.

@nodejs/fs @nodejs/documentation

@thefourtheye thefourtheye added doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. labels Jul 10, 2016
@thefourtheye thefourtheye force-pushed the fs-truncate-docs branch 2 times, most recently from e35369e to f0f04e5 Compare July 10, 2016 22:19
@thefourtheye
Copy link
Contributor Author

* `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.
Copy link
Member

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() and ftruncate() functions cause the regular file named by path or referenced by fd to be truncated to a size of precisely length 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?

Copy link
Contributor Author

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?

Copy link
Member

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').

@jasnell
Copy link
Member

jasnell commented Aug 8, 2016

LGTM with a couple of nits.
ping @addaleax

@addaleax
Copy link
Member

addaleax commented Aug 8, 2016

@thefourtheye feel free to do with my suggestion whatever you prefer, this LGTM either way!

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.
@thefourtheye
Copy link
Contributor Author

@addaleax @jasnell Rebased and addressed comments. PTAL.

For example, the following program retains only the first four bytes of the file

```js
console.log(fs.readFileSync('temp.txt', 'utf8');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: missing )

@addaleax
Copy link
Member

Left a few comments, this still LGTM! :)

@thefourtheye
Copy link
Contributor Author

Thanks for pointing them out @addaleax. I fixed them, except the over-truncation (couldn't think of anything better :()

@addaleax
Copy link
Member

Thanks! As far as I am concerned this seems good to go.

@addaleax
Copy link
Member

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
Copy link
Member

jasnell commented Aug 27, 2016

LGTM!

thefourtheye added a commit that referenced this pull request Aug 27, 2016
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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
thefourtheye added a commit that referenced this pull request Aug 27, 2016
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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
@thefourtheye
Copy link
Contributor Author

Thanks for the review. Landed in c8619ea and 82c7a9c

@thefourtheye thefourtheye deleted the fs-truncate-docs branch August 27, 2016 14:25
@Fishrock123 Fishrock123 mentioned this pull request Sep 6, 2016
Fishrock123 pushed a commit to Fishrock123/node that referenced this pull request Sep 8, 2016
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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Fishrock123 pushed a commit to Fishrock123/node that referenced this pull request Sep 8, 2016
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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Fishrock123 pushed a commit that referenced this pull request Sep 9, 2016
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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Fishrock123 pushed a commit that referenced this pull request Sep 9, 2016
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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

this is not landing cleanly on v4.x. Please feel free to manually backport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants