UNPKG

1.3 kBJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5"use strict";
6
7function 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}
65module.exports = SyncAsyncFileSystemDecorator;