| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 539e123 commit da494ef
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2554,14 +2554,18 @@ fs.readFile('<directory>', (err, data) => { | |||
| 2554 | 2554 | }); | |
| 2555 | 2555 | ``` | |
| 2556 | 2556 | ||
| 2557 | - Any specified file descriptor has to support reading. | ||
| 2558 | - | ||
| 2559 | - If a file descriptor is specified as the `path`, it will not be closed | ||
| 2560 | - automatically. | ||
| 2561 | - | ||
| 2562 | 2557 | The `fs.readFile()` function buffers the entire file. To minimize memory costs, | |
| 2563 | 2558 | when possible prefer streaming via `fs.createReadStream()`. | |
| 2564 | 2559 | ||
| 2560 | + ### File Descriptors | ||
| 2561 | + 1. Any specified file descriptor has to support reading. | ||
| 2562 | + 2. If a file descriptor is specified as the `path`, it will not be closed | ||
| 2563 | + automatically. | ||
| 2564 | + 3. The reading will begin at the current position. For example, if the file | ||
| 2565 | + already had `'Hello World`' and six bytes are read with the file descriptor, | ||
| 2566 | + the call to `fs.readFile()` with the same file descriptor, would give | ||
| 2567 | + `'World'`, rather than `'Hello World'`. | ||
| 2568 | + | ||
| 2565 | 2569 | ## fs.readFileSync(path[, options]) | |
| 2566 | 2570 | <!-- YAML | |
| 2567 | 2571 | added: v0.1.8 | |
@@ -3547,14 +3551,19 @@ If `options` is a string, then it specifies the encoding: | |||
| 3547 | 3551 | fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback); | |
| 3548 | 3552 | ``` | |
| 3549 | 3553 | ||
| 3550 | - Any specified file descriptor has to support writing. | ||
| 3551 | - | ||
| 3552 | 3554 | It is unsafe to use `fs.writeFile()` multiple times on the same file without | |
| 3553 | 3555 | waiting for the callback. For this scenario, [`fs.createWriteStream()`][] is | |
| 3554 | 3556 | recommended. | |
| 3555 | 3557 | ||
| 3556 | - If a file descriptor is specified as the `file`, it will not be closed | ||
| 3558 | + ### File Descriptors | ||
| 3559 | + 1. Any specified file descriptor has to support writing. | ||
| 3560 | + 2. If a file descriptor is specified as the `file`, it will not be closed | ||
| 3557 | 3561 | automatically. | |
| 3562 | + 3. The writing will begin at the beginning of the file. For example, if the | ||
| 3563 | + file already had `'Hello World'` and the newly written content is `'Aloha'`, | ||
| 3564 | + then the contents of the file would be `'Aloha World'`, rather than just | ||
| 3565 | + `'Aloha'`. | ||
| 3566 | + | ||
| 3558 | 3567 | ||
| 3559 | 3568 | ## fs.writeFileSync(file, data[, options]) | |
| 3560 | 3569 | <!-- YAML | |
@@ -3787,6 +3796,11 @@ returned. | |||
| 3787 | 3796 | ||
| 3788 | 3797 | The `FileHandle` has to support reading. | |
| 3789 | 3798 | ||
| 3799 | + If one or more `filehandle.read()` calls are made on a file handle and then a | ||
| 3800 | + `filehandle.readFile()` call is made, the data will be read from the current | ||
| 3801 | + position till the end of the file. It doesn't always read from the beginning | ||
| 3802 | + of the file. | ||
| 3803 | + | ||
| 3790 | 3804 | #### filehandle.stat([options]) | |
| 3791 | 3805 | <!-- YAML | |
| 3792 | 3806 | added: v10.0.0 | |
@@ -3949,6 +3963,11 @@ The `FileHandle` has to support writing. | |||
| 3949 | 3963 | It is unsafe to use `filehandle.writeFile()` multiple times on the same file | |
| 3950 | 3964 | without waiting for the `Promise` to be resolved (or rejected). | |
| 3951 | 3965 | ||
| 3966 | + If one or more `filehandle.write()` calls are made on a file handle and then a | ||
| 3967 | + `filehandle.writeFile()` call is made, the data will be written from the | ||
| 3968 | + current position till the end of the file. It doesn't always write from the | ||
| 3969 | + beginning of the file. | ||
| 3970 | + | ||
| 3952 | 3971 | ### fsPromises.access(path[, mode]) | |
| 3953 | 3972 | <!-- YAML | |
| 3954 | 3973 | added: v10.0.0 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments