Skip to content

Commit

Permalink
doc: fs.*File() also accept encoding strings
Browse files Browse the repository at this point in the history
Fixes: #1797
PR-URL: #1806
Reviewed-By: [email protected]
  • Loading branch information
Trott authored and Fishrock123 committed May 27, 2015
1 parent 1bbf8d0 commit ff79449
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions doc/api/fs.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ Synchronous version of `fs.read`. Returns the number of `bytesRead`.
## fs.readFile(filename[, options], callback)

* `filename` {String}
* `options` {Object}
* `options` {Object | String}
* `encoding` {String | Null} default = `null`
* `flag` {String} default = `'r'`
* `callback` {Function}
Expand All @@ -472,6 +472,10 @@ contents of the file.

If no encoding is specified, then the raw buffer is returned.

If `options` is a string, then it specifies the encoding. Example:

fs.readFile('/etc/passwd', 'utf8', callback);


## fs.readFileSync(filename[, options])

Expand All @@ -485,7 +489,7 @@ string. Otherwise it returns a buffer.

* `filename` {String}
* `data` {String | Buffer}
* `options` {Object}
* `options` {Object | String}
* `encoding` {String | Null} default = `'utf8'`
* `mode` {Number} default = `0o666`
* `flag` {String} default = `'w'`
Expand All @@ -504,6 +508,10 @@ Example:
console.log('It\'s saved!');
});

If `options` is a string, then it specifies the encoding. Example:

fs.writeFile('message.txt', 'Hello io.js', 'utf8', callback);

## fs.writeFileSync(filename, data[, options])

The synchronous version of `fs.writeFile`.
Expand All @@ -512,7 +520,7 @@ The synchronous version of `fs.writeFile`.

* `filename` {String}
* `data` {String | Buffer}
* `options` {Object}
* `options` {Object | String}
* `encoding` {String | Null} default = `'utf8'`
* `mode` {Number} default = `0o666`
* `flag` {String} default = `'a'`
Expand All @@ -528,6 +536,10 @@ Example:
console.log('The "data to append" was appended to file!');
});

If `options` is a string, then it specifies the encoding. Example:

fs.appendFile('message.txt', 'data to append', 'utf8', callback);

## fs.appendFileSync(filename, data[, options])

The synchronous version of `fs.appendFile`.
Expand Down

0 comments on commit ff79449

Please sign in to comment.