aboutsummaryrefslogtreecommitdiff
path: root/node_modules/fs-extra/docs/fs-read-write.md
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2019-10-06 21:37:45 +0200
committerDimitri Staessens <[email protected]>2019-10-06 21:37:45 +0200
commit3c51c3be85bb0d1bdb87ea0d6632f1c256912f27 (patch)
treec7ccc8279b12c4f7bdbbb4270d617e48f51722e4 /node_modules/fs-extra/docs/fs-read-write.md
parent412c104bebc507bea9c94fd53b5bdc4b64cbfe31 (diff)
downloadwebsite-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.tar.gz
website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.zip
build: Add some required modules for node
Diffstat (limited to 'node_modules/fs-extra/docs/fs-read-write.md')
-rw-r--r--node_modules/fs-extra/docs/fs-read-write.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/node_modules/fs-extra/docs/fs-read-write.md b/node_modules/fs-extra/docs/fs-read-write.md
new file mode 100644
index 0000000..805ea3c
--- /dev/null
+++ b/node_modules/fs-extra/docs/fs-read-write.md
@@ -0,0 +1,39 @@
+# About `fs.read()` & `fs.write()`
+
+[`fs.read()`](https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback) & [`fs.write()`](https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback) are different from other `fs` methods in that their callbacks are called with 3 arguments instead of the usual 2 arguments.
+
+If you're using them with callbacks, they will behave as usual. However, their promise usage is a little different. `fs-extra` promisifies these methods like [`util.promisify()`](https://nodejs.org/api/util.html#util_util_promisify_original) (only available in Node 8+) does.
+
+Here's the example promise usage:
+
+## `fs.read()`
+
+```js
+// Basic promises
+fs.read(fd, buffer, offset, length, position)
+ .then(results => {
+ console.log(results)
+ // { bytesRead: 20, buffer: <Buffer 0f 34 5d ...> }
+ })
+
+// Async/await usage:
+async function example () {
+ const { bytesRead, buffer } = await fs.read(fd, Buffer.alloc(length), offset, length, position)
+}
+```
+
+## `fs.write()`
+
+```js
+// Basic promises
+fs.write(fd, buffer, offset, length, position)
+ .then(results => {
+ console.log(results)
+ // { bytesWritten: 20, buffer: <Buffer 0f 34 5d ...> }
+ })
+
+// Async/await usage:
+async function example () {
+ const { bytesWritten, buffer } = await fs.write(fd, Buffer.alloc(length), offset, length, position)
+}
+```