Last change
on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
700 bytes
|
Line | |
---|
1 | # `patchFs(vol[, fs])`
|
---|
2 |
|
---|
3 | Rewrites Node's filesystem module `fs` with *fs-like* object.
|
---|
4 |
|
---|
5 | - `vol` - fs-like object
|
---|
6 | - `fs` *(optional)* - a filesystem to patch, defaults to `require('fs')`
|
---|
7 |
|
---|
8 | ```js
|
---|
9 | import {patchFs} from 'fs-monkey';
|
---|
10 |
|
---|
11 | const myfs = {
|
---|
12 | readFileSync: () => 'hello world',
|
---|
13 | };
|
---|
14 |
|
---|
15 | patchFs(myfs);
|
---|
16 | console.log(require('fs').readFileSync('/foo/bar')); // hello world
|
---|
17 | ```
|
---|
18 |
|
---|
19 | You don't need to create *fs-like* objects yourself, use [`memfs`](https://github.com/streamich/memfs)
|
---|
20 | to create a virtual filesystem for you:
|
---|
21 |
|
---|
22 | ```js
|
---|
23 | import {vol} from 'memfs';
|
---|
24 | import {patchFs} from 'fs-monkey';
|
---|
25 |
|
---|
26 | vol.fromJSON({'/dir/foo': 'bar'});
|
---|
27 | patchFs(vol);
|
---|
28 | console.log(require('fs').readdirSync('/')); // [ 'dir' ]
|
---|
29 | ```
|
---|
Note:
See
TracBrowser
for help on using the repository browser.