unionfs 组合文件npm包参考使用
unionfs 是一个灵活强大的组合fs npm 包,可以方便的进行多fs 实现的组合,比如基于内存的fs 与本地fs 组合实现强大的
npm 扩展以及配置管理。。。
参考代码
- package.json
{
"name": "mem-fs-app",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"fs-monkey": "^1.0.3",
"linkfs": "^2.1.0",
"memfs": "^3.2.2",
"unionfs": "^4.4.0"
}
}
- app.js
const {vol} = require('memfs');
const {patchRequire} = require('fs-monkey');
const {ufs} = require('unionfs');
const myfs = require('fs');
vol.fromJSON({'/foo/bar.js': 'console.log("obi trice");'});
ufs
.use(vol)
.use(myfs);
patchRequire(ufs);
require('/foo/bar.js');
运行效果
参考资料
https://github.com/streamich/unionfs
https://github.com/streamich/memfs
https://github.com/harish2704/node-s3-fs
https://github.com/streamich/linkfs