|
15 | 15 | function SyncAsyncFileSystemDecorator(fs) {
|
16 | 16 | this.fs = fs;
|
17 | 17 |
|
18 |
| - this.lstat = (arg, callback) => { |
19 |
| - let result; |
20 |
| - try { |
21 |
| - result = fs.lstatSync(arg); |
22 |
| - } catch (e) { |
23 |
| - return callback(e); |
24 |
| - } |
25 |
| - callback(null, result); |
26 |
| - }; |
27 |
| - this.lstatSync = arg => fs.lstatSync(arg); |
| 18 | + this.lstat = undefined; |
| 19 | + this.lstatSync = undefined; |
| 20 | + const lstatSync = fs.lstatSync; |
| 21 | + if (lstatSync) { |
| 22 | + this.lstat = (arg, options, callback) => { |
| 23 | + let result; |
| 24 | + try { |
| 25 | + result = lstatSync.call(fs, arg); |
| 26 | + } catch (e) { |
| 27 | + return (callback || options)(e); |
| 28 | + } |
| 29 | + (callback || options)(null, result); |
| 30 | + }; |
| 31 | + this.lstatSync = (arg, options) => lstatSync.call(fs, arg, options); |
| 32 | + } |
28 | 33 |
|
29 |
| - this.stat = (arg, callback) => { |
| 34 | + this.stat = (arg, options, callback) => { |
30 | 35 | let result;
|
31 | 36 | try {
|
32 |
| - result = fs.statSync(arg); |
| 37 | + result = fs.statSync(arg, options); |
33 | 38 | } catch (e) {
|
34 |
| - return callback(e); |
| 39 | + return (callback || options)(e); |
35 | 40 | }
|
36 |
| - callback(null, result); |
| 41 | + (callback || options)(null, result); |
37 | 42 | };
|
38 |
| - this.statSync = arg => fs.statSync(arg); |
| 43 | + this.statSync = (arg, options) => fs.statSync(arg, options); |
39 | 44 |
|
40 |
| - this.readdir = (arg, callback) => { |
| 45 | + this.readdir = (arg, options, callback) => { |
41 | 46 | let result;
|
42 | 47 | try {
|
43 | 48 | result = fs.readdirSync(arg);
|
44 | 49 | } catch (e) {
|
45 |
| - return callback(e); |
| 50 | + return (callback || options)(e); |
46 | 51 | }
|
47 |
| - callback(null, result); |
| 52 | + (callback || options)(null, result); |
48 | 53 | };
|
49 |
| - this.readdirSync = arg => fs.readdirSync(arg); |
| 54 | + this.readdirSync = (arg, options) => fs.readdirSync(arg, options); |
50 | 55 |
|
51 |
| - this.readFile = (arg, callback) => { |
| 56 | + this.readFile = (arg, options, callback) => { |
52 | 57 | let result;
|
53 | 58 | try {
|
54 | 59 | result = fs.readFileSync(arg);
|
55 | 60 | } catch (e) {
|
56 |
| - return callback(e); |
| 61 | + return (callback || options)(e); |
57 | 62 | }
|
58 |
| - callback(null, result); |
| 63 | + (callback || options)(null, result); |
59 | 64 | };
|
60 |
| - this.readFileSync = arg => fs.readFileSync(arg); |
| 65 | + this.readFileSync = (arg, options) => fs.readFileSync(arg, options); |
61 | 66 |
|
62 |
| - this.readlink = (arg, callback) => { |
| 67 | + this.readlink = (arg, options, callback) => { |
63 | 68 | let result;
|
64 | 69 | try {
|
65 | 70 | result = fs.readlinkSync(arg);
|
66 | 71 | } catch (e) {
|
67 |
| - return callback(e); |
| 72 | + return (callback || options)(e); |
68 | 73 | }
|
69 |
| - callback(null, result); |
| 74 | + (callback || options)(null, result); |
70 | 75 | };
|
71 |
| - this.readlinkSync = arg => fs.readlinkSync(arg); |
| 76 | + this.readlinkSync = (arg, options) => fs.readlinkSync(arg, options); |
72 | 77 |
|
73 | 78 | this.readJson = undefined;
|
74 | 79 | this.readJsonSync = undefined;
|
75 | 80 | const readJsonSync = fs.readJsonSync;
|
76 | 81 | if (readJsonSync) {
|
77 |
| - this.readJson = (arg, callback) => { |
| 82 | + this.readJson = (arg, options, callback) => { |
78 | 83 | let result;
|
79 | 84 | try {
|
80 | 85 | result = readJsonSync.call(fs, arg);
|
81 | 86 | } catch (e) {
|
82 |
| - return callback(e); |
| 87 | + return (callback || options)(e); |
83 | 88 | }
|
84 |
| - callback(null, result); |
| 89 | + (callback || options)(null, result); |
85 | 90 | };
|
86 | 91 |
|
87 |
| - this.readJsonSync = arg => readJsonSync.call(fs, arg); |
| 92 | + this.readJsonSync = (arg, options) => readJsonSync.call(fs, arg, options); |
88 | 93 | }
|
89 | 94 | }
|
90 | 95 | module.exports = SyncAsyncFileSystemDecorator;
|
0 commit comments