Bind methods to instance
Description
Native fs methods work without binding, but memfs methods don't
Native fs
const fs = require('fs');
const { readFile } = fs;
readFile('package.json', console.log);
Memfs
const { Volume } = require('memfs');
const fs = Volume.fromJSON({ '/package.json': 'test' });
const { readFile } = fs;
readFile('package.json', console.log);
Get the following error due to a lack of binding:
TypeError: Cannot read property 'wrapAsync' of undefined at Volume.readFile (memfs/lib/volume.js:957:14)
Motivation
A lot of libraries still use promisify instead of calling the native fs promise API:
const mkdir = promisify(options.fs.mkdir);
Source: https://github.com/sindresorhus/make-dir/blob/master/index.js#L50
In this use-case, using memfs breaks due to the error above
Expected behavior
For all memfs methods to be bound to the Volume instance.
Maybe we should do that in the future.
But for now we have createFsFromVolume method to achieve this behavior.
Ah nice, thank you.
I think it will be more intuitive if it's on by default since I use memfs as a drop-in replacement to fs.