Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createNewMemoryFileSystem(): MemoryFileSystem {
const _fs = new MemoryFileSystem();
// Note: binding all methods of _fs
// some libs use individual fs method
// e.g const writeFileSync = fs.writeFileSync
// writeFileSync() // this will call method with wrong this
// happening in find-config package
Object.keys(MemoryFileSystem.prototype).forEach((key) => {
if (typeof _fs[key] === 'function') {
_fs[key] = _fs[key].bind(_fs);
}
});
return _fs;
}
const MemoryFileSystem = require('memory-fs');
const fs = new MemoryFileSystem();
for (let f in MemoryFileSystem.prototype) {
if (typeof MemoryFileSystem.prototype[f] === 'function') {
fs[f] = MemoryFileSystem.prototype[f].bind(fs);
}
}
fs.lstat = fs.stat;
fs.lstatSync = fs.statSync;
const readFileSync = fs.readFileSync;
fs.readFileSync = (path, encoding) => {
if (encoding && encoding.encoding) encoding = encoding.encoding;
return readFileSync(path, encoding);
};
const createWriteStream = fs.createWriteStream;
fs.createWriteStream = path => {
const s = createWriteStream(path);
return {
const MemoryFileSystem = require('memory-fs');
const fs = new MemoryFileSystem();
for (let f in MemoryFileSystem.prototype) {
if (typeof MemoryFileSystem.prototype[f] === 'function') {
fs[f] = MemoryFileSystem.prototype[f].bind(fs);
}
}
fs.lstat = fs.stat;
fs.lstatSync = fs.statSync;
const readFileSync = fs.readFileSync;
fs.readFileSync = (path, encoding) => {
if (encoding && encoding.encoding) encoding = encoding.encoding;
return readFileSync(path, encoding);
};
const createWriteStream = fs.createWriteStream;
fs.createWriteStream = path => {
const s = createWriteStream(path);