UNPKG

1.84 kBMarkdownView Raw
1# fs-promise
2
3[![Build Status](https://secure.travis-ci.org/kevinbeaty/fs-promise.svg)](http://travis-ci.org/kevinbeaty/fs-promise)
4
5
6```javascript
7var fsp = require('fs-promise');
8
9fsp.writeFile(file('hello1'), 'hello world')
10 .then(function(){
11 return fsp.readFile(file('hello1'), {encoding:'utf8'});
12 })
13 .then(function(contents){});
14```
15
16## Implementation
17
18`fs-promise` is now a thin wrapper on top of [`mz/fs`][4] adding support for async functions from [`fs-extra`][2]. If you do not need the functions from `fs-extra`, consider using `mz` directly.
19
20* Proxies async [`fs`][1] and [`fs-extra`][2] methods exposing them as ES 2015 (ES6) compatible promises.
21* Uses [any-promise][3] to load preferred `Promise` implementation.
22* Directly uses [mz/fs][4] for all `fs` functions.
23* Proxies `walk` from `fs-extra` to resolve Promise as arrays of items.
24* Proxies the following functions from fs-extra using [thenify-all][5]. (Proxies all other functions directly).
25
26```javascript
27[
28 'copy',
29 'emptyDir',
30 'ensureFile',
31 'ensureDir',
32 'ensureLink'
33 'ensureSymlink',
34 'mkdirs',
35 'move',
36 'outputFile',
37 'outputJson',
38 'readJson',
39 'remove',
40 'writeJson'
41]
42```
43
44## Usage
45
46Detects a `Promise` implementation using [`any-promise`][3]. If you have a preferred implementation, or are working in an environment without a global implementation, you must explicitly register a `Promise` implementation and it will be used. See [`any-promise`][3] for details.
47
48Typical installation:
49
50```bash
51$ npm install --save fs-promise
52```
53
54Note that `fs-extra` depends on `graceful-fs`, so you will get the benefits of both libraries.
55
56[1]: https://nodejs.org/api/fs.html
57[2]: https://www.npmjs.org/package/fs-extra
58[3]: https://github.com/kevinbeaty/any-promise
59[4]: https://github.com/normalize/mz
60[5]: https://github.com/thenables/thenify-all