Last active
December 13, 2015 22:49
-
-
Save chrismytton/4986885 to your computer and use it in GitHub Desktop.
HTML5 FileSystem API
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Filesystem test</title> | |
</head> | |
<body> | |
<script> | |
function handleError(error) { | |
console.warn("An error occurred", error) | |
} | |
var requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem | |
window.webkitStorageInfo.requestQuota(window.PERSISTENT, 50*1024*1024, function(grantedBytes) { | |
requestFileSystem(window.PERSISTENT, grantedBytes, function(fileSystem) { | |
fileSystem.root.getDirectory('Documents', {create: true, exclusive: false}, function(directoryEntry) { | |
directoryEntry.getFile('text/lorem.txt', {create: true, exclusive: false}, function(file) { | |
file.createWriter(function(writer) { | |
writer.onwrite = function() { | |
console.log("File was written successfully") | |
} | |
writer.onerror = handleError | |
writer.write(new Blob([new Uint8Array("Lorem ipsum dolar sit amet")])) | |
}, handleError) | |
}, handleError) | |
}, handleError) | |
}, handleError) | |
}, handleError) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment