Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
doc: review comments
  • Loading branch information
thefourtheye committed Aug 27, 2016
commit d0b96ec8f4c176fccf448286feeab2d0daf29e40
7 changes: 4 additions & 3 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ the first `len` bytes will be retained in the file.
For example, the following program retains only the first four bytes of the file

```js
console.log(fs.readFileSync('temp.txt', 'utf8');
console.log(fs.readFileSync('temp.txt', 'utf8'));
// prints Node.js

// get the file descriptor of the file to be truncated
Expand All @@ -769,7 +769,7 @@ If the file previously was shorter than `len` bytes, it is extended, and the
extended part is filled with null bytes ('\0'). For example,

```js
fs.readFileSync('temp.txt', 'utf-8');
console.log(fs.readFileSync('temp.txt', 'utf-8'));
// prints Node.js

// get the file descriptor of the file to be truncated
Expand All @@ -781,9 +781,10 @@ fs.ftruncate(fd, 10, (err) => {
console.log(fs.readFileSync('temp.txt'));
});
// prints <Buffer 4e 6f 64 65 2e 6a 73 00 00 00>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a suggestion, but maybe add a second line like this?

  // prints <Buffer 4e 6f 64 65 2e 6a 73 00 00 00>
  // ('Node.js\0\0\0' in UTF8)

// ('Node.js\0\0\0' in UTF8)
```

The last three bytes are zeroes, to compensate the over-truncation.
The last three bytes are null bytes ('\0'), to compensate the over-truncation.

## fs.ftruncateSync(fd, len)
<!-- YAML
Expand Down