Skip to content

Commit d7390ae

Browse files
committed
add 'fs.promises' API to 'fs' plugin docs
1 parent 45e536f commit d7390ae

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

docs/plugin_fs.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ Hop over to the [Browser QuickStart](./guide-browser.md) to see how that's done.
2525
2626
### Implementing your own `fs` plugin
2727

28+
There are actually TWO ways to implement an `fs` plugin: the classic "callback" API and the newer "promise" API. If your `fs` plugin object provides a `promises` property, `isomorphic-git` will use the "promise" API _exclusively_.
2829

29-
An `fs` plugin must implement the following subset of node's `fs` module:
30+
#### Using the "callback" API
31+
32+
A "callback" `fs` plugin must implement the following subset of node's `fs` module:
3033
- [fs.readFile(path[, options], callback)](https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback)
3134
- [fs.writeFile(file, data[, options], callback)](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback)
3235
- [fs.unlink(path, callback)](https://nodejs.org/api/fs.html#fs_fs_unlink_path_callback)
@@ -37,3 +40,24 @@ An `fs` plugin must implement the following subset of node's `fs` module:
3740
- [fs.lstat(path[, options], callback)](https://nodejs.org/api/fs.html#fs_fs_lstat_path_options_callback)
3841
- [fs.readlink(path[, options], callback)](https://nodejs.org/api/fs.html#fs_fs_readlink_path_options_callback)
3942
- [fs.symlink(target, path[, type], callback)](https://nodejs.org/api/fs.html#fs_fs_symlink_target_path_type_callback)
43+
44+
Internally, `isomorphic-git` wraps the provided "callback" API functions using [`pify`](https://www.npmjs.com/package/pify).
45+
46+
As of node v12 the `fs.promises` API has been stabilized. (`lightning-fs` also provides a `fs.promises` API!) Nowadays, wrapping the callback functions
47+
with `pify` is redundant and potentially less performant than using the native promisified versions. Plus, if you're writing your own `fs` plugin,
48+
the `fs.promises` API lets you write straightforward implementations using `async / await` without the messy optional argument handling the callback API needs.
49+
Therefore a second API is now supported...
50+
51+
#### Using the "promise" API (preferred)
52+
53+
A "promise" `fs` plugin must implement the same set functions as a "callback" plugin, but it implements the promisified versions, and they should all be on a property called `promises`:
54+
- [fs.promises.readFile(path[, options])](https://nodejs.org/api/fs.html#fs_fspromises_readfile_path_options)
55+
- [fs.promises.writeFile(file, data[, options])](https://nodejs.org/api/fs.html#fs_fspromises_writefile_file_data_options)
56+
- [fs.promises.unlink(path)](https://nodejs.org/api/fs.html#fs_fspromises_unlink_path)
57+
- [fs.promises.readdir(path[, options])](https://nodejs.org/api/fs.html#fs_fspromises_readdir_path_options)
58+
- [fs.promises.mkdir(path[, mode])](https://nodejs.org/api/fs.html#fs_fspromises_mkdir_path_options)
59+
- [fs.promises.rmdir(path)](https://nodejs.org/api/fs.html#fs_fspromises_rmdir_path)
60+
- [fs.promises.stat(path[, options])](https://nodejs.org/api/fs.html#fs_fspromises_stat_path_options)
61+
- [fs.promises.lstat(path[, options])](https://nodejs.org/api/fs.html#fs_fspromises_lstat_path_options)
62+
- [fs.promises.readlink(path[, options])](https://nodejs.org/api/fs.html#fs_fspromises_readlink_path_options)
63+
- [fs.promises.symlink(target, path[, type])](https://nodejs.org/api/fs.html#fs_fspromises_symlink_target_path_type)

0 commit comments

Comments
 (0)