@@ -479,8 +479,8 @@ fs.appendFile('message.txt', 'data to append', 'utf8', callback);
479
479
480
480
Any specified file descriptor has to have been opened for appending.
481
481
482
- _ Note : If a file descriptor is specified as the ` file ` , it will not be closed
483
- automatically._
482
+ * Note * : If a file descriptor is specified as the ` file ` , it will not be closed
483
+ automatically.
484
484
485
485
## fs.appendFileSync(file, data[ , options] )
486
486
<!-- YAML
@@ -1248,10 +1248,10 @@ On Linux, positional writes don't work when the file is opened in append mode.
1248
1248
The kernel ignores the position argument and always appends the data to
1249
1249
the end of the file.
1250
1250
1251
- _ Note : The behavior of ` fs.open() ` is platform specific for some flags. As such,
1251
+ * Note * : The behavior of ` fs.open() ` is platform- specific for some flags. As such,
1252
1252
opening a directory on macOS and Linux with the ` 'a+' ` flag - see example
1253
1253
below - will return an error. In contrast, on Windows and FreeBSD, a file
1254
- descriptor will be returned._
1254
+ descriptor will be returned.
1255
1255
1256
1256
``` js
1257
1257
// macOS and Linux
@@ -1368,11 +1368,27 @@ If `options` is a string, then it specifies the encoding. Example:
1368
1368
``` js
1369
1369
fs .readFile (' /etc/passwd' , ' utf8' , callback);
1370
1370
```
1371
+ * Note* : When the path is a directory, the behavior of
1372
+ ` fs.readFile() ` and [ ` fs.readFileSync() ` ] [ ] is platform-specific. On macOS,
1373
+ Linux, and Windows, an error will be returned. On FreeBSD, a representation
1374
+ of the directory's contents will be returned.
1375
+
1376
+ ``` js
1377
+ // macOS, Linux and Windows
1378
+ fs .readFile (' <directory>' , (err , data ) => {
1379
+ // => [Error: EISDIR: illegal operation on a directory, read <directory>]
1380
+ });
1381
+
1382
+ // FreeBSD
1383
+ fs .readFile (' <directory>' , (err , data ) => {
1384
+ // => null, <data>
1385
+ });
1386
+ ```
1371
1387
1372
1388
Any specified file descriptor has to support reading.
1373
1389
1374
- _ Note : If a file descriptor is specified as the ` file ` , it will not be closed
1375
- automatically._
1390
+ * Note * : If a file descriptor is specified as the ` path ` , it will not be closed
1391
+ automatically.
1376
1392
1377
1393
## fs.readFileSync(file[ , options] )
1378
1394
<!-- YAML
@@ -1389,6 +1405,18 @@ Synchronous version of [`fs.readFile`][]. Returns the contents of the `file`.
1389
1405
If the ` encoding ` option is specified then this function returns a
1390
1406
string. Otherwise it returns a buffer.
1391
1407
1408
+ * Note* : Similar to [ ` fs.readFile() ` ] [ ] , when the path is a directory, the
1409
+ behavior of ` fs.readFileSync() ` is platform-specific.
1410
+
1411
+ ``` js
1412
+ // macOS, Linux and Windows
1413
+ fs .readFileSync (' <directory>' );
1414
+ // => [Error: EISDIR: illegal operation on a directory, read <directory>]
1415
+
1416
+ // FreeBSD
1417
+ fs .readFileSync (' <directory>' ); // => null, <data>
1418
+ ```
1419
+
1392
1420
## fs.readlink(path[ , options] , callback)
1393
1421
<!-- YAML
1394
1422
added: v0.1.31
@@ -1641,9 +1669,9 @@ have effectively stopped watching `filename`.
1641
1669
Calling ` fs.unwatchFile() ` with a filename that is not being watched is a
1642
1670
no-op, not an error.
1643
1671
1644
- _ Note : [ ` fs.watch() ` ] [ ] is more efficient than ` fs.watchFile() ` and ` fs.unwatchFile() ` .
1672
+ * Note * : [ ` fs.watch() ` ] [ ] is more efficient than ` fs.watchFile() ` and ` fs.unwatchFile() ` .
1645
1673
` fs.watch() ` should be used instead of ` fs.watchFile() ` and ` fs.unwatchFile() `
1646
- when possible._
1674
+ when possible.
1647
1675
1648
1676
## fs.utimes(path, atime, mtime, callback)
1649
1677
<!-- YAML
@@ -1817,15 +1845,15 @@ These stat objects are instances of `fs.Stat`.
1817
1845
If you want to be notified when the file was modified, not just accessed,
1818
1846
you need to compare ` curr.mtime ` and ` prev.mtime ` .
1819
1847
1820
- _ Note : when an ` fs.watchFile ` operation results in an ` ENOENT ` error, it will
1848
+ * Note * : when an ` fs.watchFile ` operation results in an ` ENOENT ` error, it will
1821
1849
invoke the listener once, with all the fields zeroed (or, for dates, the Unix
1822
1850
Epoch). In Windows, ` blksize ` and ` blocks ` fields will be ` undefined ` , instead
1823
1851
of zero. If the file is created later on, the listener will be called again,
1824
- with the latest stat objects. This is a change in functionality since v0.10._
1852
+ with the latest stat objects. This is a change in functionality since v0.10.
1825
1853
1826
- _ Note : [ ` fs.watch() ` ] [ ] is more efficient than ` fs.watchFile ` and
1854
+ * Note * : [ ` fs.watch() ` ] [ ] is more efficient than ` fs.watchFile ` and
1827
1855
` fs.unwatchFile ` . ` fs.watch ` should be used instead of ` fs.watchFile ` and
1828
- ` fs.unwatchFile ` when possible._
1856
+ ` fs.unwatchFile ` when possible.
1829
1857
1830
1858
## fs.write(fd, buffer, offset, length[ , position] , callback)
1831
1859
<!-- YAML
@@ -1935,8 +1963,8 @@ Note that it is unsafe to use `fs.writeFile` multiple times on the same file
1935
1963
without waiting for the callback. For this scenario,
1936
1964
` fs.createWriteStream ` is strongly recommended.
1937
1965
1938
- _ Note : If a file descriptor is specified as the ` file ` , it will not be closed
1939
- automatically._
1966
+ * Note * : If a file descriptor is specified as the ` file ` , it will not be closed
1967
+ automatically.
1940
1968
1941
1969
## fs.writeFileSync(file, data[ , options] )
1942
1970
<!-- YAML
0 commit comments