Comparing version 0.1.0 to 0.1.1
@@ -23,3 +23,3 @@ /* | ||
if(!nix) { | ||
if(!/^[A-Za-z]:/.test(path)) throw new Error("Invalid path " + path); | ||
if(!/^[A-Za-z]:/.test(path)) throw new Error("Invalid path '" + path + "'"); | ||
path = path.replace(/[\\\/]+/g, "\\"); // multi slashs | ||
@@ -36,4 +36,4 @@ path = path.split(/[\\\/]/); | ||
function trueFn() { return true } | ||
function falseFn() { return false } | ||
function trueFn() { return true; } | ||
function falseFn() { return false; } | ||
@@ -45,3 +45,3 @@ MemoryFileSystem.prototype.statSync = function(_path) { | ||
if(!isDir(current[path[i]])) | ||
throw new Error("Path doesn't exists " + _path); | ||
throw new Error("Path doesn't exist '" + _path + "'"); | ||
current = current[path[i]]; | ||
@@ -70,3 +70,3 @@ } | ||
} else | ||
throw new Error("Path doesn't exists " + _path); | ||
throw new Error("Path doesn't exist '" + _path + "'"); | ||
}; | ||
@@ -79,3 +79,3 @@ | ||
if(!isDir(current[path[i]])) | ||
throw new Error("Path doesn't exists " + _path); | ||
throw new Error("Path doesn't exist '" + _path + "'"); | ||
current = current[path[i]]; | ||
@@ -85,5 +85,5 @@ } | ||
if(isDir(current[path[i]])) | ||
throw new Error("Cannot readFile on directory " + _path); | ||
throw new Error("Cannot readFile on directory '" + _path + "'"); | ||
else | ||
throw new Error("File doesn't exists " + _path); | ||
throw new Error("Path doesn't exist '" + _path + "'"); | ||
} | ||
@@ -100,3 +100,3 @@ current = current[path[i]]; | ||
if(!isDir(current[path[i]])) | ||
throw new Error("Path doesn't exists " + _path); | ||
throw new Error("Path doesn't exist '" + _path + "'"); | ||
current = current[path[i]]; | ||
@@ -106,5 +106,5 @@ } | ||
if(isFile(current[path[i]])) | ||
throw new Error("Cannot readdir on file " + _path); | ||
throw new Error("Cannot readdir on file '" + _path + "'"); | ||
else | ||
throw new Error("File doesn't exists " + _path); | ||
throw new Error("Path doesn't exist '" + _path + "'"); | ||
} | ||
@@ -120,3 +120,3 @@ return Object.keys(current[path[i]]).filter(Boolean); | ||
if(isFile(current[path[i]])) | ||
throw new Error("Path is a file " + _path); | ||
throw new Error("Path is a file '" + _path + "'"); | ||
else if(!isDir(current[path[i]])) | ||
@@ -135,9 +135,9 @@ current[path[i]] = {"":true}; | ||
if(!isDir(current[path[i]])) | ||
throw new Error("Path doesn't exists " + _path); | ||
throw new Error("Path doesn't exist '" + _path + "'"); | ||
current = current[path[i]]; | ||
} | ||
if(isDir(current[path[i]])) | ||
throw new new Error("Directory already exist " + _path); | ||
throw new new Error("Directory already exist '" + _path + "'"); | ||
else if(isFile(current[path[i]])) | ||
throw new Error("Cannot mkdir on file " + _path); | ||
throw new Error("Cannot mkdir on file '" + _path + "'"); | ||
current[path[i]] = {"":true}; | ||
@@ -149,11 +149,11 @@ return; | ||
var path = pathToArray(_path); | ||
if(path.length === 0) throw new Error("Path cannot be removed " + _path); | ||
if(path.length === 0) throw new Error("Path cannot be removed '" + _path + "'"); | ||
var current = this.data; | ||
for(var i = 0; i < path.length - 1; i++) { | ||
if(!isDir(current[path[i]])) | ||
throw new Error("Path doesn't exists " + _path); | ||
throw new Error("Path doesn't exist '" + _path + "'"); | ||
current = current[path[i]]; | ||
} | ||
if(!testFn(current[path[i]])) | ||
throw new Error(name + " doesn't exist " + _path); | ||
throw new Error("'" + name + "' doesn't exist '" + _path + "'"); | ||
delete current[path[i]]; | ||
@@ -174,11 +174,11 @@ return; | ||
var path = pathToArray(_path); | ||
if(path.length === 0) throw new Error("Path is not a file " + _path); | ||
if(path.length === 0) throw new Error("Path is not a file '" + _path + "'"); | ||
var current = this.data; | ||
for(var i = 0; i < path.length - 1; i++) { | ||
if(!isDir(current[path[i]])) | ||
throw new Error("Path doesn't exists " + _path); | ||
throw new Error("Path doesn't exist '" + _path + "'"); | ||
current = current[path[i]]; | ||
} | ||
if(isDir(current[path[i]])) | ||
throw new Error("Cannot writeFile on directory " + _path); | ||
throw new Error("Cannot writeFile on directory '" + _path + "'"); | ||
current[path[i]] = encoding || typeof content === "string" ? new Buffer(content, encoding) : content; | ||
@@ -194,3 +194,3 @@ return; | ||
// sync functions | ||
// async functions | ||
@@ -208,18 +208,16 @@ ["stat", "readdir", "mkdirp", "mkdir", "rmdir", "unlink"].forEach(function(fn) { | ||
["readFile"].forEach(function(fn) { | ||
MemoryFileSystem.prototype[fn] = function(path, optArg, callback) { | ||
if(!callback) { | ||
callback = optArg; | ||
optArg = undefined; | ||
} | ||
try { | ||
var result = this[fn + "Sync"](path, optArg); | ||
} catch(e) { | ||
return callback(e); | ||
} | ||
return callback(null, result); | ||
}; | ||
}); | ||
MemoryFileSystem.prototype.readFile = function(path, optArg, callback) { | ||
if(!callback) { | ||
callback = optArg; | ||
optArg = undefined; | ||
} | ||
try { | ||
var result = this.readFileSync(path, optArg); | ||
} catch(e) { | ||
return callback(e); | ||
} | ||
return callback(null, result); | ||
}; | ||
MemoryFileSystem.prototype.writeFile = function writeFile(path, content, encoding, callback) { | ||
MemoryFileSystem.prototype.writeFile = function (path, content, encoding, callback) { | ||
if(!callback) { | ||
@@ -226,0 +224,0 @@ callback = encoding; |
{ | ||
"name": "memory-fs", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A simple in-memory filesystem. Holds data in a javascript object.", | ||
@@ -5,0 +5,0 @@ "main": "lib/MemoryFileSystem.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16627
7
421