Skip to content

Instantly share code, notes, and snippets.

@yossan
Created August 19, 2020 15:18
Show Gist options
  • Save yossan/25e66361225d1c20b7626343798e3e82 to your computer and use it in GitHub Desktop.
Save yossan/25e66361225d1c20b7626343798e3e82 to your computer and use it in GitHub Desktop.
Web/API/FileSystem
<html> <head> <title>ファイルを書き込む</title> <meta charset="utf-8">
</head>
<body>
<script>
function onInitFs(fs) {
fs.root.getFile('log3.txt', {create: true}, function(fileEntry) {
// Create a FileWriter object for our FileSystemFileEntry (log.txt).
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
console.log('Write completed.');
};
fileWriter.onerror = function(e) {
console.log('Write failed: ' + e.toString());
};
// Create a new Blob and write it to log.txt.
var bb = new Blob(['Hello World'], {type: 'text/plain'});
fileWriter.write(bb);
}, (err) => {console.log(err)});
}, (err) => {console.log(err)});
}
navigator.webkitPersistentStorage.requestQuota(1024*1024*5, function(bytes) {
window.webkitRequestFileSystem(window.PERSISTENT, bytes, onInitFs, (err)=>{console.log(err)});
})
</script>
</body>
</html>
@yossan
Copy link
Author

yossan commented Aug 19, 2020

@yossan
Copy link
Author

yossan commented Aug 19, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment