Externalized ensureFileDoesntExist

pull/2/head
Louis Chatriot 10 years ago
parent b0e3ceb1a6
commit 857d89066f
  1. 10
      browser-version/browser-specific/lib/storage.js
  2. 5
      lib/customUtils.js
  3. 10
      lib/persistence.js
  4. 2
      package.json

@ -70,11 +70,21 @@ function readFile (filename, options, callback) {
} }
function unlink (filenqme, callback) {
if (typeof localStorage === 'undefined') { console.log("WARNING - This browser doesn't support localStorage, no data will be saved in NeDB!"); return callback(); }
localStorage.removeItem(filename);
return callback();
}
// Interface // Interface
module.exports.exists = exists; module.exports.exists = exists;
module.exports.rename = rename; module.exports.rename = rename;
module.exports.writeFile = writeFile; module.exports.writeFile = writeFile;
module.exports.appendFile = appendFile; module.exports.appendFile = appendFile;
module.exports.readFile = readFile; module.exports.readFile = readFile;
module.exports.unlink = unlink;

@ -18,9 +18,6 @@ function uid (len) {
} }
/**
* Callback signature: err
*/
function ensureFileDoesntExist (file, callback) { function ensureFileDoesntExist (file, callback) {
fs.exists(file, function (exists) { fs.exists(file, function (exists) {
if (!exists) { return callback(null); } if (!exists) { return callback(null); }
@ -30,5 +27,7 @@ function ensureFileDoesntExist (file, callback) {
} }
// Interface
module.exports.uid = uid; module.exports.uid = uid;
module.exports.ensureFileDoesntExist = ensureFileDoesntExist; module.exports.ensureFileDoesntExist = ensureFileDoesntExist;

@ -16,6 +16,16 @@ var fs = require('fs')
; ;
// Helper
function ensureFileDoesntExist (file, callback) {
storage.exists(file, function (exists) {
if (!exists) { return callback(null); }
storage.unlink(file, function (err) { return callback(err); });
});
}
/** /**
* Create a new Persistence object for database options.db * Create a new Persistence object for database options.db
* @param {Datastore} options.db * @param {Datastore} options.db

@ -38,7 +38,7 @@
}, },
"browser": { "browser": {
"./lib/customUtils.js": "./browser-version/browser-specific/lib/customUtils.js", "./lib/customUtils.js": "./browser-version/browser-specific/lib/customUtils.js",
"./lib/persistence.js": "./browser-version/browser-specific/lib/persistence.js" "./lib/storage.js": "./browser-version/browser-specific/lib/storage.js"
}, },
"main": "index", "main": "index",
"licence": "MIT" "licence": "MIT"

Loading…
Cancel
Save