Browse Source

doc: update readFileSync in fs.md

* Updated fs.md stating fs.readFileAsync is platform specific
* Fix formatting of `note`s

PR-URL: https://github.com/nodejs/node/pull/12800
Refs: https://github.com/nodejs/node/issues/10962
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v6.x
Aditya Anand 8 years ago
committed by Myles Borins
parent
commit
3b1d9112e0
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 56
      doc/api/fs.md

56
doc/api/fs.md

@ -479,8 +479,8 @@ fs.appendFile('message.txt', 'data to append', 'utf8', callback);
Any specified file descriptor has to have been opened for appending. Any specified file descriptor has to have been opened for appending.
_Note: If a file descriptor is specified as the `file`, it will not be closed *Note*: If a file descriptor is specified as the `file`, it will not be closed
automatically._ automatically.
## fs.appendFileSync(file, data[, options]) ## fs.appendFileSync(file, data[, options])
<!-- YAML <!-- YAML
@ -1248,10 +1248,10 @@ On Linux, positional writes don't work when the file is opened in append mode.
The kernel ignores the position argument and always appends the data to The kernel ignores the position argument and always appends the data to
the end of the file. the end of the file.
_Note: The behavior of `fs.open()` is platform specific for some flags. As such, *Note*: The behavior of `fs.open()` is platform-specific for some flags. As such,
opening a directory on macOS and Linux with the `'a+'` flag - see example opening a directory on macOS and Linux with the `'a+'` flag - see example
below - will return an error. In contrast, on Windows and FreeBSD, a file below - will return an error. In contrast, on Windows and FreeBSD, a file
descriptor will be returned._ descriptor will be returned.
```js ```js
// macOS and Linux // macOS and Linux
@ -1368,11 +1368,27 @@ If `options` is a string, then it specifies the encoding. Example:
```js ```js
fs.readFile('/etc/passwd', 'utf8', callback); fs.readFile('/etc/passwd', 'utf8', callback);
``` ```
*Note*: When the path is a directory, the behavior of
`fs.readFile()` and [`fs.readFileSync()`][] is platform-specific. On macOS,
Linux, and Windows, an error will be returned. On FreeBSD, a representation
of the directory's contents will be returned.
```js
// macOS, Linux and Windows
fs.readFile('<directory>', (err, data) => {
// => [Error: EISDIR: illegal operation on a directory, read <directory>]
});
// FreeBSD
fs.readFile('<directory>', (err, data) => {
// => null, <data>
});
```
Any specified file descriptor has to support reading. Any specified file descriptor has to support reading.
_Note: If a file descriptor is specified as the `file`, it will not be closed *Note*: If a file descriptor is specified as the `path`, it will not be closed
automatically._ automatically.
## fs.readFileSync(file[, options]) ## fs.readFileSync(file[, options])
<!-- YAML <!-- YAML
@ -1389,6 +1405,18 @@ Synchronous version of [`fs.readFile`][]. Returns the contents of the `file`.
If the `encoding` option is specified then this function returns a If the `encoding` option is specified then this function returns a
string. Otherwise it returns a buffer. string. Otherwise it returns a buffer.
*Note*: Similar to [`fs.readFile()`][], when the path is a directory, the
behavior of `fs.readFileSync()` is platform-specific.
```js
// macOS, Linux and Windows
fs.readFileSync('<directory>');
// => [Error: EISDIR: illegal operation on a directory, read <directory>]
// FreeBSD
fs.readFileSync('<directory>'); // => null, <data>
```
## fs.readlink(path[, options], callback) ## fs.readlink(path[, options], callback)
<!-- YAML <!-- YAML
added: v0.1.31 added: v0.1.31
@ -1641,9 +1669,9 @@ have effectively stopped watching `filename`.
Calling `fs.unwatchFile()` with a filename that is not being watched is a Calling `fs.unwatchFile()` with a filename that is not being watched is a
no-op, not an error. no-op, not an error.
_Note: [`fs.watch()`][] is more efficient than `fs.watchFile()` and `fs.unwatchFile()`. *Note*: [`fs.watch()`][] is more efficient than `fs.watchFile()` and `fs.unwatchFile()`.
`fs.watch()` should be used instead of `fs.watchFile()` and `fs.unwatchFile()` `fs.watch()` should be used instead of `fs.watchFile()` and `fs.unwatchFile()`
when possible._ when possible.
## fs.utimes(path, atime, mtime, callback) ## fs.utimes(path, atime, mtime, callback)
<!-- YAML <!-- YAML
@ -1817,15 +1845,15 @@ These stat objects are instances of `fs.Stat`.
If you want to be notified when the file was modified, not just accessed, If you want to be notified when the file was modified, not just accessed,
you need to compare `curr.mtime` and `prev.mtime`. you need to compare `curr.mtime` and `prev.mtime`.
_Note: when an `fs.watchFile` operation results in an `ENOENT` error, it will *Note*: when an `fs.watchFile` operation results in an `ENOENT` error, it will
invoke the listener once, with all the fields zeroed (or, for dates, the Unix invoke the listener once, with all the fields zeroed (or, for dates, the Unix
Epoch). In Windows, `blksize` and `blocks` fields will be `undefined`, instead Epoch). In Windows, `blksize` and `blocks` fields will be `undefined`, instead
of zero. If the file is created later on, the listener will be called again, of zero. If the file is created later on, the listener will be called again,
with the latest stat objects. This is a change in functionality since v0.10._ with the latest stat objects. This is a change in functionality since v0.10.
_Note: [`fs.watch()`][] is more efficient than `fs.watchFile` and *Note*: [`fs.watch()`][] is more efficient than `fs.watchFile` and
`fs.unwatchFile`. `fs.watch` should be used instead of `fs.watchFile` and `fs.unwatchFile`. `fs.watch` should be used instead of `fs.watchFile` and
`fs.unwatchFile` when possible._ `fs.unwatchFile` when possible.
## fs.write(fd, buffer, offset, length[, position], callback) ## fs.write(fd, buffer, offset, length[, position], callback)
<!-- YAML <!-- YAML
@ -1935,8 +1963,8 @@ Note that it is unsafe to use `fs.writeFile` multiple times on the same file
without waiting for the callback. For this scenario, without waiting for the callback. For this scenario,
`fs.createWriteStream` is strongly recommended. `fs.createWriteStream` is strongly recommended.
_Note: If a file descriptor is specified as the `file`, it will not be closed *Note*: If a file descriptor is specified as the `file`, it will not be closed
automatically._ automatically.
## fs.writeFileSync(file, data[, options]) ## fs.writeFileSync(file, data[, options])
<!-- YAML <!-- YAML

Loading…
Cancel
Save