@@ -40,7 +40,7 @@ MemoryFileSystem.prototype.statSync = function(_path) {
40
40
var current = this . data ;
41
41
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
42
42
if ( ! isDir ( current [ path [ i ] ] ) )
43
- throw new Error ( "Path doesn't exists " + _path ) ;
43
+ throw new Error ( "Path doesn't exist " + _path ) ;
44
44
current = current [ path [ i ] ] ;
45
45
}
46
46
if ( _path === "/" || isDir ( current [ path [ i ] ] ) ) {
@@ -64,22 +64,22 @@ MemoryFileSystem.prototype.statSync = function(_path) {
64
64
isSocket : falseFn
65
65
} ;
66
66
} else
67
- throw new Error ( "Path doesn't exists " + _path ) ;
67
+ throw new Error ( "Path doesn't exist " + _path ) ;
68
68
} ;
69
69
70
70
MemoryFileSystem . prototype . readFileSync = function ( _path , encoding ) {
71
71
var path = pathToArray ( _path ) ;
72
72
var current = this . data ;
73
73
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
74
74
if ( ! isDir ( current [ path [ i ] ] ) )
75
- throw new Error ( "Path doesn't exists " + _path ) ;
75
+ throw new Error ( "Path doesn't exist " + _path ) ;
76
76
current = current [ path [ i ] ] ;
77
77
}
78
78
if ( ! isFile ( current [ path [ i ] ] ) ) {
79
79
if ( isDir ( current [ path [ i ] ] ) )
80
80
throw new Error ( "Cannot readFile on directory " + _path ) ;
81
81
else
82
- throw new Error ( "File doesn't exists " + _path ) ;
82
+ throw new Error ( "File doesn't exist " + _path ) ;
83
83
}
84
84
current = current [ path [ i ] ] ;
85
85
return encoding ? current . toString ( encoding ) : current ;
@@ -91,14 +91,14 @@ MemoryFileSystem.prototype.readdirSync = function(_path) {
91
91
var current = this . data ;
92
92
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
93
93
if ( ! isDir ( current [ path [ i ] ] ) )
94
- throw new Error ( "Path doesn't exists " + _path ) ;
94
+ throw new Error ( "Path doesn't exist " + _path ) ;
95
95
current = current [ path [ i ] ] ;
96
96
}
97
97
if ( ! isDir ( current [ path [ i ] ] ) ) {
98
98
if ( isFile ( current [ path [ i ] ] ) )
99
99
throw new Error ( "Cannot readdir on file " + _path ) ;
100
100
else
101
- throw new Error ( "File doesn't exists " + _path ) ;
101
+ throw new Error ( "File doesn't exist " + _path ) ;
102
102
}
103
103
return Object . keys ( current [ path [ i ] ] ) . filter ( Boolean ) ;
104
104
} ;
@@ -123,7 +123,7 @@ MemoryFileSystem.prototype.mkdirSync = function(_path) {
123
123
var current = this . data ;
124
124
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
125
125
if ( ! isDir ( current [ path [ i ] ] ) )
126
- throw new Error ( "Path doesn't exists " + _path ) ;
126
+ throw new Error ( "Path doesn't exist " + _path ) ;
127
127
current = current [ path [ i ] ] ;
128
128
}
129
129
if ( isDir ( current [ path [ i ] ] ) )
@@ -140,7 +140,7 @@ MemoryFileSystem.prototype._remove = function(_path, name, testFn) {
140
140
var current = this . data ;
141
141
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
142
142
if ( ! isDir ( current [ path [ i ] ] ) )
143
- throw new Error ( "Path doesn't exists " + _path ) ;
143
+ throw new Error ( "Path doesn't exist " + _path ) ;
144
144
current = current [ path [ i ] ] ;
145
145
}
146
146
if ( ! testFn ( current [ path [ i ] ] ) )
@@ -164,7 +164,7 @@ MemoryFileSystem.prototype.writeFileSync = function(_path, content, encoding) {
164
164
var current = this . data ;
165
165
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
166
166
if ( ! isDir ( current [ path [ i ] ] ) )
167
- throw new Error ( "Path doesn't exists " + _path ) ;
167
+ throw new Error ( "Path doesn't exist " + _path ) ;
168
168
current = current [ path [ i ] ] ;
169
169
}
170
170
if ( isDir ( current [ path [ i ] ] ) )
@@ -179,7 +179,7 @@ MemoryFileSystem.prototype.join = function(a, b) {
179
179
return a + "/" + b ;
180
180
} ;
181
181
182
- // sync functions
182
+ // async functions
183
183
184
184
[ "stat" , "readdir" , "mkdirp" , "mkdir" , "rmdir" , "unlink" ] . forEach ( function ( fn ) {
185
185
MemoryFileSystem . prototype [ fn ] = function ( path , callback ) {
@@ -192,22 +192,20 @@ MemoryFileSystem.prototype.join = function(a, b) {
192
192
} ;
193
193
} ) ;
194
194
195
- [ "readFile" ] . forEach ( function ( fn ) {
196
- MemoryFileSystem . prototype [ fn ] = function ( path , optArg , callback ) {
197
- if ( ! callback ) {
198
- callback = optArg ;
199
- optArg = undefined ;
200
- }
201
- try {
202
- var result = this [ fn + "Sync" ] ( path , optArg ) ;
203
- } catch ( e ) {
204
- return callback ( e ) ;
205
- }
206
- return callback ( null , result ) ;
207
- } ;
208
- } ) ;
195
+ MemoryFileSystem . prototype . readFile = function ( path , optArg , callback ) {
196
+ if ( ! callback ) {
197
+ callback = optArg ;
198
+ optArg = undefined ;
199
+ }
200
+ try {
201
+ var result = this . readFileSync ( path , optArg ) ;
202
+ } catch ( e ) {
203
+ return callback ( e ) ;
204
+ }
205
+ return callback ( null , result ) ;
206
+ } ;
209
207
210
- MemoryFileSystem . prototype . writeFile = function writeFile ( path , content , encoding , callback ) {
208
+ MemoryFileSystem . prototype . writeFile = function ( path , content , encoding , callback ) {
211
209
if ( ! callback ) {
212
210
callback = encoding ;
213
211
encoding = undefined ;
0 commit comments