Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit 7e8a7db

Browse files
committed
Merge pull request #2 from mjackson/tweaks
Small Tweaks
2 parents 65991b3 + 5521797 commit 7e8a7db

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

lib/MemoryFileSystem.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ MemoryFileSystem.prototype.statSync = function(_path) {
4040
var current = this.data;
4141
for(var i = 0; i < path.length - 1; i++) {
4242
if(!isDir(current[path[i]]))
43-
throw new Error("Path doesn't exists " + _path);
43+
throw new Error("Path doesn't exist " + _path);
4444
current = current[path[i]];
4545
}
4646
if(_path === "/" || isDir(current[path[i]])) {
@@ -64,22 +64,22 @@ MemoryFileSystem.prototype.statSync = function(_path) {
6464
isSocket: falseFn
6565
};
6666
} else
67-
throw new Error("Path doesn't exists " + _path);
67+
throw new Error("Path doesn't exist " + _path);
6868
};
6969

7070
MemoryFileSystem.prototype.readFileSync = function(_path, encoding) {
7171
var path = pathToArray(_path);
7272
var current = this.data;
7373
for(var i = 0; i < path.length - 1; i++) {
7474
if(!isDir(current[path[i]]))
75-
throw new Error("Path doesn't exists " + _path);
75+
throw new Error("Path doesn't exist " + _path);
7676
current = current[path[i]];
7777
}
7878
if(!isFile(current[path[i]])) {
7979
if(isDir(current[path[i]]))
8080
throw new Error("Cannot readFile on directory " + _path);
8181
else
82-
throw new Error("File doesn't exists " + _path);
82+
throw new Error("File doesn't exist " + _path);
8383
}
8484
current = current[path[i]];
8585
return encoding ? current.toString(encoding) : current;
@@ -91,14 +91,14 @@ MemoryFileSystem.prototype.readdirSync = function(_path) {
9191
var current = this.data;
9292
for(var i = 0; i < path.length - 1; i++) {
9393
if(!isDir(current[path[i]]))
94-
throw new Error("Path doesn't exists " + _path);
94+
throw new Error("Path doesn't exist " + _path);
9595
current = current[path[i]];
9696
}
9797
if(!isDir(current[path[i]])) {
9898
if(isFile(current[path[i]]))
9999
throw new Error("Cannot readdir on file " + _path);
100100
else
101-
throw new Error("File doesn't exists " + _path);
101+
throw new Error("File doesn't exist " + _path);
102102
}
103103
return Object.keys(current[path[i]]).filter(Boolean);
104104
};
@@ -123,7 +123,7 @@ MemoryFileSystem.prototype.mkdirSync = function(_path) {
123123
var current = this.data;
124124
for(var i = 0; i < path.length - 1; i++) {
125125
if(!isDir(current[path[i]]))
126-
throw new Error("Path doesn't exists " + _path);
126+
throw new Error("Path doesn't exist " + _path);
127127
current = current[path[i]];
128128
}
129129
if(isDir(current[path[i]]))
@@ -140,7 +140,7 @@ MemoryFileSystem.prototype._remove = function(_path, name, testFn) {
140140
var current = this.data;
141141
for(var i = 0; i < path.length - 1; i++) {
142142
if(!isDir(current[path[i]]))
143-
throw new Error("Path doesn't exists " + _path);
143+
throw new Error("Path doesn't exist " + _path);
144144
current = current[path[i]];
145145
}
146146
if(!testFn(current[path[i]]))
@@ -164,7 +164,7 @@ MemoryFileSystem.prototype.writeFileSync = function(_path, content, encoding) {
164164
var current = this.data;
165165
for(var i = 0; i < path.length - 1; i++) {
166166
if(!isDir(current[path[i]]))
167-
throw new Error("Path doesn't exists " + _path);
167+
throw new Error("Path doesn't exist " + _path);
168168
current = current[path[i]];
169169
}
170170
if(isDir(current[path[i]]))
@@ -179,7 +179,7 @@ MemoryFileSystem.prototype.join = function(a, b) {
179179
return a + "/" + b;
180180
};
181181

182-
// sync functions
182+
// async functions
183183

184184
["stat", "readdir", "mkdirp", "mkdir", "rmdir", "unlink"].forEach(function(fn) {
185185
MemoryFileSystem.prototype[fn] = function(path, callback) {
@@ -192,22 +192,20 @@ MemoryFileSystem.prototype.join = function(a, b) {
192192
};
193193
});
194194

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+
};
209207

210-
MemoryFileSystem.prototype.writeFile = function writeFile(path, content, encoding, callback) {
208+
MemoryFileSystem.prototype.writeFile = function (path, content, encoding, callback) {
211209
if(!callback) {
212210
callback = encoding;
213211
encoding = undefined;

0 commit comments

Comments
 (0)