Last active
August 29, 2015 14:10
-
-
Save jessep/e62421cfae5a038664c1 to your computer and use it in GitHub Desktop.
Crosswalk Failing Storage test [fixed]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I figured it out. You have to requestQuota | |
// before requestFileSystem with PERSISTENT storage | |
var INITIALIZATION_DATA_FILENAME = 'test.json'; | |
function getQuotaThenStoreFile(){ | |
window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024, function(grantedBytes) { | |
//window.requestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler); | |
testStoringFile(grantedBytes); | |
}, function(e) { | |
console.log('Error', e); | |
}); | |
} | |
function testStoringFile(quotaGranted){ | |
window.requestFileSystem(window.PERSISTENT, quotaGranted, function(filesystem) { | |
var fs = filesystem; | |
fs.root.getFile(INITIALIZATION_DATA_FILENAME, {create: true}, function(fileEntry) { | |
fileEntry.file(function(file) { | |
var reader = new FileReader(); | |
reader.onloadend = function(e) { | |
if (this.result.length > 0) { | |
callback(JSON.parse(this.result), 1000); | |
} else { | |
// Tell the app that we don't have any initialization data | |
callback(undefined, null); | |
} | |
}; | |
reader.readAsText(file); | |
}, errorHandler); | |
}, errorHandler); | |
}, errorHandler); | |
} | |
function errorHandler(e) { | |
console.log('file error: ', e.name, ', ', e.message); | |
} | |
function callback(initializationData) { | |
console.log("initialization data:", initializationData); | |
} | |
getQuotaThenStoreFile(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment