This commit is contained in:
Alan K 2014-06-23 14:31:58 -04:00
parent d38d1d0b6d
commit c3681d4db6
4 changed files with 266 additions and 268 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "filer", "name": "filer",
"version": "0.0.11", "version": "0.0.12",
"main": "dist/filer.js", "main": "dist/filer.js",
"devDependencies": { "devDependencies": {
"mocha": "1.17.1", "mocha": "1.17.1",

120
dist/filer.js vendored
View File

@ -14811,23 +14811,23 @@ module.exports = {
}; };
},{"./indexeddb.js":56,"./memory.js":57,"./websql.js":58}],56:[function(_dereq_,module,exports){ },{"./indexeddb.js":56,"./memory.js":57,"./websql.js":58}],56:[function(_dereq_,module,exports){
(function(global) { (function (global){
var FILE_SYSTEM_NAME = _dereq_('../constants.js').FILE_SYSTEM_NAME; var FILE_SYSTEM_NAME = _dereq_('../constants.js').FILE_SYSTEM_NAME;
var FILE_STORE_NAME = _dereq_('../constants.js').FILE_STORE_NAME; var FILE_STORE_NAME = _dereq_('../constants.js').FILE_STORE_NAME;
var IDB_RW = _dereq_('../constants.js').IDB_RW; var IDB_RW = _dereq_('../constants.js').IDB_RW;
var IDB_RO = _dereq_('../constants.js').IDB_RO; var IDB_RO = _dereq_('../constants.js').IDB_RO;
var Errors = _dereq_('../errors.js'); var Errors = _dereq_('../errors.js');
var indexedDB = global.indexedDB || var indexedDB = global.indexedDB ||
global.mozIndexedDB || global.mozIndexedDB ||
global.webkitIndexedDB || global.webkitIndexedDB ||
global.msIndexedDB; global.msIndexedDB;
function IndexedDBContext(db, mode) { function IndexedDBContext(db, mode) {
var transaction = db.transaction(FILE_STORE_NAME, mode); var transaction = db.transaction(FILE_STORE_NAME, mode);
this.objectStore = transaction.objectStore(FILE_STORE_NAME); this.objectStore = transaction.objectStore(FILE_STORE_NAME);
} }
IndexedDBContext.prototype.clear = function(callback) { IndexedDBContext.prototype.clear = function(callback) {
try { try {
var request = this.objectStore.clear(); var request = this.objectStore.clear();
request.onsuccess = function(event) { request.onsuccess = function(event) {
@ -14839,8 +14839,8 @@ module.exports = {
} catch(e) { } catch(e) {
callback(e); callback(e);
} }
}; };
IndexedDBContext.prototype.get = function(key, callback) { IndexedDBContext.prototype.get = function(key, callback) {
try { try {
var request = this.objectStore.get(key); var request = this.objectStore.get(key);
request.onsuccess = function onsuccess(event) { request.onsuccess = function onsuccess(event) {
@ -14853,8 +14853,8 @@ module.exports = {
} catch(e) { } catch(e) {
callback(e); callback(e);
} }
}; };
IndexedDBContext.prototype.put = function(key, value, callback) { IndexedDBContext.prototype.put = function(key, value, callback) {
try { try {
var request = this.objectStore.put(value, key); var request = this.objectStore.put(value, key);
request.onsuccess = function onsuccess(event) { request.onsuccess = function onsuccess(event) {
@ -14867,8 +14867,8 @@ module.exports = {
} catch(e) { } catch(e) {
callback(e); callback(e);
} }
}; };
IndexedDBContext.prototype.delete = function(key, callback) { IndexedDBContext.prototype.delete = function(key, callback) {
try { try {
var request = this.objectStore.delete(key); var request = this.objectStore.delete(key);
request.onsuccess = function onsuccess(event) { request.onsuccess = function onsuccess(event) {
@ -14881,18 +14881,18 @@ module.exports = {
} catch(e) { } catch(e) {
callback(e); callback(e);
} }
}; };
function IndexedDB(name) { function IndexedDB(name) {
this.name = name || FILE_SYSTEM_NAME; this.name = name || FILE_SYSTEM_NAME;
this.db = null; this.db = null;
} }
IndexedDB.isSupported = function() { IndexedDB.isSupported = function() {
return !!indexedDB; return !!indexedDB;
}; };
IndexedDB.prototype.open = function(callback) { IndexedDB.prototype.open = function(callback) {
var that = this; var that = this;
// Bail if we already have a db open // Bail if we already have a db open
@ -14927,21 +14927,20 @@ module.exports = {
openRequest.onerror = function onerror(error) { openRequest.onerror = function onerror(error) {
callback(new Errors.EINVAL('IndexedDB cannot be accessed. If private browsing is enabled, disable it.')); callback(new Errors.EINVAL('IndexedDB cannot be accessed. If private browsing is enabled, disable it.'));
}; };
}; };
IndexedDB.prototype.getReadOnlyContext = function() { IndexedDB.prototype.getReadOnlyContext = function() {
// Due to timing issues in Chrome with readwrite vs. readonly indexeddb transactions // Due to timing issues in Chrome with readwrite vs. readonly indexeddb transactions
// always use readwrite so we can make sure pending commits finish before callbacks. // always use readwrite so we can make sure pending commits finish before callbacks.
// See https://github.com/js-platform/filer/issues/128 // See https://github.com/js-platform/filer/issues/128
return new IndexedDBContext(this.db, IDB_RW); return new IndexedDBContext(this.db, IDB_RW);
}; };
IndexedDB.prototype.getReadWriteContext = function() { IndexedDB.prototype.getReadWriteContext = function() {
return new IndexedDBContext(this.db, IDB_RW); return new IndexedDBContext(this.db, IDB_RW);
}; };
module.exports = IndexedDB; module.exports = IndexedDB;
}(this));
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"../constants.js":44,"../errors.js":47}],57:[function(_dereq_,module,exports){ },{"../constants.js":44,"../errors.js":47}],57:[function(_dereq_,module,exports){
var FILE_SYSTEM_NAME = _dereq_('../constants.js').FILE_SYSTEM_NAME; var FILE_SYSTEM_NAME = _dereq_('../constants.js').FILE_SYSTEM_NAME;
var asyncCallback = _dereq_('../../lib/async.js').nextTick; var asyncCallback = _dereq_('../../lib/async.js').nextTick;
@ -15032,16 +15031,16 @@ Memory.prototype.getReadWriteContext = function() {
module.exports = Memory; module.exports = Memory;
},{"../../lib/async.js":1,"../constants.js":44}],58:[function(_dereq_,module,exports){ },{"../../lib/async.js":1,"../constants.js":44}],58:[function(_dereq_,module,exports){
(function(global) { (function (global){
var FILE_SYSTEM_NAME = _dereq_('../constants.js').FILE_SYSTEM_NAME; var FILE_SYSTEM_NAME = _dereq_('../constants.js').FILE_SYSTEM_NAME;
var FILE_STORE_NAME = _dereq_('../constants.js').FILE_STORE_NAME; var FILE_STORE_NAME = _dereq_('../constants.js').FILE_STORE_NAME;
var WSQL_VERSION = _dereq_('../constants.js').WSQL_VERSION; var WSQL_VERSION = _dereq_('../constants.js').WSQL_VERSION;
var WSQL_SIZE = _dereq_('../constants.js').WSQL_SIZE; var WSQL_SIZE = _dereq_('../constants.js').WSQL_SIZE;
var WSQL_DESC = _dereq_('../constants.js').WSQL_DESC; var WSQL_DESC = _dereq_('../constants.js').WSQL_DESC;
var u8toArray = _dereq_('../shared.js').u8toArray; var u8toArray = _dereq_('../shared.js').u8toArray;
var Errors = _dereq_('../errors.js'); var Errors = _dereq_('../errors.js');
function WebSQLContext(db, isReadOnly) { function WebSQLContext(db, isReadOnly) {
var that = this; var that = this;
this.getTransaction = function(callback) { this.getTransaction = function(callback) {
if(that.transaction) { if(that.transaction) {
@ -15054,8 +15053,8 @@ module.exports = Memory;
callback(transaction); callback(transaction);
}); });
}; };
} }
WebSQLContext.prototype.clear = function(callback) { WebSQLContext.prototype.clear = function(callback) {
function onError(transaction, error) { function onError(transaction, error) {
callback(error); callback(error);
} }
@ -15066,8 +15065,8 @@ module.exports = Memory;
transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + ";", transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + ";",
[], onSuccess, onError); [], onSuccess, onError);
}); });
}; };
WebSQLContext.prototype.get = function(key, callback) { WebSQLContext.prototype.get = function(key, callback) {
function onSuccess(transaction, result) { function onSuccess(transaction, result) {
// If the key isn't found, return null // If the key isn't found, return null
var value = result.rows.length === 0 ? null : result.rows.item(0).data; var value = result.rows.length === 0 ? null : result.rows.item(0).data;
@ -15091,8 +15090,8 @@ module.exports = Memory;
transaction.executeSql("SELECT data FROM " + FILE_STORE_NAME + " WHERE id = ?;", transaction.executeSql("SELECT data FROM " + FILE_STORE_NAME + " WHERE id = ?;",
[key], onSuccess, onError); [key], onSuccess, onError);
}); });
}; };
WebSQLContext.prototype.put = function(key, value, callback) { WebSQLContext.prototype.put = function(key, value, callback) {
// We do extra work to make sure typed arrays survive // We do extra work to make sure typed arrays survive
// being stored in the db and still get the right prototype later. // being stored in the db and still get the right prototype later.
if(Object.prototype.toString.call(value) === "[object Uint8Array]") { if(Object.prototype.toString.call(value) === "[object Uint8Array]") {
@ -15112,8 +15111,8 @@ module.exports = Memory;
transaction.executeSql("INSERT OR REPLACE INTO " + FILE_STORE_NAME + " (id, data) VALUES (?, ?);", transaction.executeSql("INSERT OR REPLACE INTO " + FILE_STORE_NAME + " (id, data) VALUES (?, ?);",
[key, value], onSuccess, onError); [key, value], onSuccess, onError);
}); });
}; };
WebSQLContext.prototype.delete = function(key, callback) { WebSQLContext.prototype.delete = function(key, callback) {
function onSuccess(transaction, result) { function onSuccess(transaction, result) {
callback(null); callback(null);
} }
@ -15124,18 +15123,18 @@ module.exports = Memory;
transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + " WHERE id = ?;", transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + " WHERE id = ?;",
[key], onSuccess, onError); [key], onSuccess, onError);
}); });
}; };
function WebSQL(name) { function WebSQL(name) {
this.name = name || FILE_SYSTEM_NAME; this.name = name || FILE_SYSTEM_NAME;
this.db = null; this.db = null;
} }
WebSQL.isSupported = function() { WebSQL.isSupported = function() {
return !!global.openDatabase; return !!global.openDatabase;
}; };
WebSQL.prototype.open = function(callback) { WebSQL.prototype.open = function(callback) {
var that = this; var that = this;
// Bail if we already have a db open // Bail if we already have a db open
@ -15182,18 +15181,17 @@ module.exports = Memory;
transaction.executeSql("CREATE TABLE IF NOT EXISTS " + FILE_STORE_NAME + " (id unique, data TEXT);", transaction.executeSql("CREATE TABLE IF NOT EXISTS " + FILE_STORE_NAME + " (id unique, data TEXT);",
[], createIndex, onError); [], createIndex, onError);
}); });
}; };
WebSQL.prototype.getReadOnlyContext = function() { WebSQL.prototype.getReadOnlyContext = function() {
return new WebSQLContext(this.db, true); return new WebSQLContext(this.db, true);
}; };
WebSQL.prototype.getReadWriteContext = function() { WebSQL.prototype.getReadWriteContext = function() {
return new WebSQLContext(this.db, false); return new WebSQLContext(this.db, false);
}; };
module.exports = WebSQL; module.exports = WebSQL;
}(this));
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"../constants.js":44,"../errors.js":47,"../shared.js":59}],59:[function(_dereq_,module,exports){ },{"../constants.js":44,"../errors.js":47,"../shared.js":59}],59:[function(_dereq_,module,exports){
function guid() { function guid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {

4
dist/filer.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,7 @@
"idb", "idb",
"websql" "websql"
], ],
"version": "0.0.11", "version": "0.0.12",
"author": "Alan K <ack@modeswitch.org> (http://blog.modeswitch.org)", "author": "Alan K <ack@modeswitch.org> (http://blog.modeswitch.org)",
"homepage": "http://js-platform.github.io/filer", "homepage": "http://js-platform.github.io/filer",
"bugs": "https://github.com/js-platform/filer/issues", "bugs": "https://github.com/js-platform/filer/issues",