Skip to content

Instantly share code, notes, and snippets.

@chrismytton
Last active December 13, 2015 22:49
Show Gist options
  • Save chrismytton/4986885 to your computer and use it in GitHub Desktop.
Save chrismytton/4986885 to your computer and use it in GitHub Desktop.
HTML5 FileSystem API
<!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