Created
September 30, 2011 10:55
-
-
Save vjeux/1253426 to your computer and use it in GitHub Desktop.
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
// Source: http://davidflanagan.com/Talks/jsconf11/BytesAndBlobs.html | |
// Load File | |
function loadBlob(path, callback) { | |
webkitRequestFileSystem( // Ask for filesystem | |
PERSISTENT, 50*1024*1024, | |
function(fs) { // When we get filesystem | |
fs.root.getFile( // Ask for a fs entry | |
path, {}, // With this name | |
function(entry) { // When we get entry | |
entry.file( // Ask for the file | |
function(f) { // When we get file | |
callback(f); // Pass to callback | |
}); | |
}); | |
}); | |
} | |
// Save File | |
function saveBlob(blob, path, done) { | |
webkitRequestFileSystem( // Ask for fs | |
PERSISTENT, // Save across sessions | |
50*1024*1024, // Allow 50Mb | |
function(fs) { // When we get the fs | |
fs.root.getFile( // Ask for a fs entry | |
path, // With specified path | |
{create:true}, // Create if needed. | |
function(entry) { // When we get entry | |
entry.createWriter( // Ask for a writer | |
function(writer) { // When we get writer | |
writer.write(blob); // Write blob | |
writer.onwrite = done; | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment