forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_fs.ts
More file actions
45 lines (40 loc) · 912 Bytes
/
node_fs.ts
File metadata and controls
45 lines (40 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {default as FS, FSModule} from './FS';
// Manually export the individual public functions of fs.
// Required because some code will invoke functions off of the module.
// e.g.:
// let writeFile = fs.writeFile;
// writeFile(...)
/**
* @hidden
*/
let fs: any = new FS();
/**
* @hidden
*/
const _fsMock: FSModule = <any> {};
/**
* @hidden
*/
const fsProto = FS.prototype;
Object.keys(fsProto).forEach((key) => {
if (typeof fs[key] === 'function') {
(<any> _fsMock)[key] = function() {
return (<Function> fs[key]).apply(fs, arguments);
};
} else {
(<any> _fsMock)[key] = fs[key];
}
});
_fsMock['changeFSModule'] = function(newFs: FS): void {
fs = newFs;
};
_fsMock['getFSModule'] = function(): FS {
return fs;
};
_fsMock['FS'] = FS;
_fsMock['Stats'] = FS.Stats;
_fsMock['F_OK'] = 0;
_fsMock['R_OK'] = 4;
_fsMock['W_OK'] = 2;
_fsMock['X_OK'] = 1;
export default _fsMock;