From f4fe770021b77c3ea36eff64d26b463fbf123d6d Mon Sep 17 00:00:00 2001 From: Valentin Heun Date: Fri, 16 Sep 2016 17:49:44 -0400 Subject: [PATCH 1/3] Safari compatibility (project file and basic demo) # led and const are not supported by safari, they are replaced with var # Safari seems to handle the asynchronous file loading process different then chrome and firefox. getAllEntries() needs to be called within onwriteend(), otherwise it produces an empty entry when a file is uploaded. --- .gitignore | 3 ++- demos/basic/js/app.js | 3 +-- src/idb.filesystem.js | 34 +++++++++++++++++++--------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index bb93d68..78dbd62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -bower_components \ No newline at end of file +bower_components +.idea \ No newline at end of file diff --git a/demos/basic/js/app.js b/demos/basic/js/app.js index 31defe8..1dc29fc 100644 --- a/demos/basic/js/app.js +++ b/demos/basic/js/app.js @@ -53,11 +53,10 @@ function writeFile(file, i) { }; fileWriter.onwriteend = function() { console.log('WRITE END'); + getAllEntries(cwd); }; fileWriter.write(file); }, onError); - - getAllEntries(cwd); }, onError); } diff --git a/src/idb.filesystem.js b/src/idb.filesystem.js index f984cbb..b97f8c1 100755 --- a/src/idb.filesystem.js +++ b/src/idb.filesystem.js @@ -34,16 +34,17 @@ if (exports.requestFileSystem || exports.webkitRequestFileSystem) { } // Bomb out if no indexedDB available -const indexedDB = exports.indexedDB || exports.mozIndexedDB || +var indexedDB = exports.indexedDB || exports.mozIndexedDB || exports.msIndexedDB; if (!indexedDB) { return; } -let IDB_SUPPORTS_BLOB = true; +var IDB_SUPPORTS_BLOB = false; + // Check to see if IndexedDB support blobs -const support = function() { + function support() { var dbName = "blob-support"; indexedDB.deleteDatabase(dbName).onsuccess = function() { var request = indexedDB.open(dbName, 1); @@ -70,7 +71,10 @@ const support = function() { }; }; -const Base64ToBlob = function(dataURL) { +// this is called to set IDB_SUPPORTS_BLOB at all times +support(); + +function Base64ToBlob(dataURL) { var BASE64_MARKER = ';base64,'; if (dataURL.indexOf(BASE64_MARKER) == -1) { var parts = dataURL.split(','); @@ -94,7 +98,7 @@ const Base64ToBlob = function(dataURL) { return new Blob([uInt8Array], {type: contentType}); }; -const BlobToBase64 = function(blob, onload) { +function BlobToBase64(blob, onload) { var reader = new FileReader(); reader.readAsDataURL(blob); reader.onloadend = function() { @@ -146,24 +150,24 @@ function MyFileError(obj) { MyFileError.prototype = FileError.prototype; MyFileError.prototype.toString = Error.prototype.toString; -const INVALID_MODIFICATION_ERR = new MyFileError({ +var INVALID_MODIFICATION_ERR = new MyFileError({ code: FileError.INVALID_MODIFICATION_ERR, name: 'INVALID_MODIFICATION_ERR'}); -const NOT_IMPLEMENTED_ERR = new MyFileError({code: 1000, +var NOT_IMPLEMENTED_ERR = new MyFileError({code: 1000, name: 'Not implemented'}); -const NOT_FOUND_ERR = new MyFileError({code: FileError.NOT_FOUND_ERR, +var NOT_FOUND_ERR = new MyFileError({code: FileError.NOT_FOUND_ERR, name: 'Not found'}); -let fs_ = null; +var fs_ = null; // Browsers other than Chrome don't implement persistent vs. temporary storage. // but default to temporary anyway. -let storageType_ = 'temporary'; -const idb_ = {db: null}; -const FILE_STORE_ = 'entries'; +var storageType_ = 'temporary'; +var idb_ = {db: null}; +var FILE_STORE_ = 'entries'; -const DIR_SEPARATOR = '/'; -const DIR_OPEN_BOUND = String.fromCharCode(DIR_SEPARATOR.charCodeAt(0) + 1); +var DIR_SEPARATOR = '/'; +var DIR_OPEN_BOUND = String.fromCharCode(DIR_SEPARATOR.charCodeAt(0) + 1); // When saving an entry, the fullPath should always lead with a slash and never // end with one (e.g. a directory). Also, resolve '.' and '..' to an absolute @@ -342,7 +346,7 @@ function FileWriter(fileEntry) { blob_ = new Blob([data], {type: data.type}); } - const writeFile = function(blob) { + var writeFile = function(blob) { // Blob might be a DataURI depending on browser support. fileEntry.file_.blob_ = blob; fileEntry.file_.lastModifiedDate = data.lastModifiedDate || new Date(); From 43d5b77ff87a9c404fd82afacc05cca6fef97ec4 Mon Sep 17 00:00:00 2001 From: Valentin Heun Date: Fri, 16 Sep 2016 18:21:36 -0400 Subject: [PATCH 2/3] API change support => setSupportsBlob --- src/idb.filesystem.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/idb.filesystem.js b/src/idb.filesystem.js index b97f8c1..9f1d16d 100755 --- a/src/idb.filesystem.js +++ b/src/idb.filesystem.js @@ -44,7 +44,7 @@ var IDB_SUPPORTS_BLOB = false; // Check to see if IndexedDB support blobs - function support() { + function setSupportsBlob() { var dbName = "blob-support"; indexedDB.deleteDatabase(dbName).onsuccess = function() { var request = indexedDB.open(dbName, 1); @@ -72,7 +72,7 @@ var IDB_SUPPORTS_BLOB = false; }; // this is called to set IDB_SUPPORTS_BLOB at all times -support(); + setSupportsBlob(); function Base64ToBlob(dataURL) { var BASE64_MARKER = ';base64,'; From f44bab0600c03a92eb7c88b8577cbfbb17f7227d Mon Sep 17 00:00:00 2001 From: Valentin Heun Date: Fri, 16 Sep 2016 18:22:23 -0400 Subject: [PATCH 3/3] ... and removed comment --- src/idb.filesystem.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/idb.filesystem.js b/src/idb.filesystem.js index 9f1d16d..2ec7890 100755 --- a/src/idb.filesystem.js +++ b/src/idb.filesystem.js @@ -71,8 +71,7 @@ var IDB_SUPPORTS_BLOB = false; }; }; -// this is called to set IDB_SUPPORTS_BLOB at all times - setSupportsBlob(); +setSupportsBlob(); function Base64ToBlob(dataURL) { var BASE64_MARKER = ';base64,';