diff --git a/browser-version/browser-specific/lib/storage.js b/browser-version/browser-specific/lib/storage.js index 210ee67..be3a2aa 100644 --- a/browser-version/browser-specific/lib/storage.js +++ b/browser-version/browser-specific/lib/storage.js @@ -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 module.exports.exists = exists; module.exports.rename = rename; module.exports.writeFile = writeFile; module.exports.appendFile = appendFile; module.exports.readFile = readFile; +module.exports.unlink = unlink; diff --git a/lib/customUtils.js b/lib/customUtils.js index 4d15f48..53109a2 100644 --- a/lib/customUtils.js +++ b/lib/customUtils.js @@ -18,9 +18,6 @@ function uid (len) { } -/** - * Callback signature: err - */ function ensureFileDoesntExist (file, callback) { fs.exists(file, function (exists) { if (!exists) { return callback(null); } @@ -30,5 +27,7 @@ function ensureFileDoesntExist (file, callback) { } +// Interface module.exports.uid = uid; module.exports.ensureFileDoesntExist = ensureFileDoesntExist; + diff --git a/lib/persistence.js b/lib/persistence.js index b080db7..4007b6d 100644 --- a/lib/persistence.js +++ b/lib/persistence.js @@ -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 * @param {Datastore} options.db diff --git a/package.json b/package.json index 6d1110a..0d08b5a 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "browser": { "./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", "licence": "MIT"