1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | function SyncAsyncFileSystemDecorator(fs) {
|
8 | this.fs = fs;
|
9 | if(fs.statSync) {
|
10 | this.stat = function(arg, callback) {
|
11 | let result;
|
12 | try {
|
13 | result = fs.statSync(arg);
|
14 | } catch(e) {
|
15 | return callback(e);
|
16 | }
|
17 | callback(null, result);
|
18 | };
|
19 | }
|
20 | if(fs.readdirSync) {
|
21 | this.readdir = function(arg, callback) {
|
22 | let result;
|
23 | try {
|
24 | result = fs.readdirSync(arg);
|
25 | } catch(e) {
|
26 | return callback(e);
|
27 | }
|
28 | callback(null, result);
|
29 | };
|
30 | }
|
31 | if(fs.readFileSync) {
|
32 | this.readFile = function(arg, callback) {
|
33 | let result;
|
34 | try {
|
35 | result = fs.readFileSync(arg);
|
36 | } catch(e) {
|
37 | return callback(e);
|
38 | }
|
39 | callback(null, result);
|
40 | };
|
41 | }
|
42 | if(fs.readlinkSync) {
|
43 | this.readlink = function(arg, callback) {
|
44 | let result;
|
45 | try {
|
46 | result = fs.readlinkSync(arg);
|
47 | } catch(e) {
|
48 | return callback(e);
|
49 | }
|
50 | callback(null, result);
|
51 | };
|
52 | }
|
53 | if(fs.readJsonSync) {
|
54 | this.readJson = function(arg, callback) {
|
55 | let result;
|
56 | try {
|
57 | result = fs.readJsonSync(arg);
|
58 | } catch(e) {
|
59 | return callback(e);
|
60 | }
|
61 | callback(null, result);
|
62 | };
|
63 | }
|
64 | }
|
65 | module.exports = SyncAsyncFileSystemDecorator;
|