Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

memory-fs

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memory-fs - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

.travis.yml

72

lib/MemoryFileSystem.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc