-
Notifications
You must be signed in to change notification settings - Fork 0
/
write.html
103 lines (79 loc) · 2.35 KB
/
write.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html>
<head>
<title>Write to File</title>
<script>
function onWriteInitFs(fs){
fs.root.getFile('log.txt', {create: true}, function(fileEntry) {
// Create a FileWriter object for our FileEntry (log.txt).
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
console.log('Write completed.');index.html
};
fileWriter.onerror = function(e) {
console.log('Write failed: ' + e.toString());
};
//Text
var someText = "This is a piece of sample text";
alert("Text written: " + someText);
// Create a new Blob and write it to log.txt.
var blob = new Blob([someText], {type: 'text/plain'});
fileWriter.write(blob);
}, errorHandler);
}, errorHandler);
}
function onClearInitFs(fs){
fs.root.getFile('log.txt', {create: true}, function(fileEntry) {
// Create a FileWriter object for our FileEntry (log.txt).
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
console.log('Clear completed.');
};
fileWriter.onerror = function(e) {
console.log('Clear failed: ' + e.toString());
};
//Text
var someText = "";
for(i = 0; i < fileWriter.length; i++)
someText = someText + " ";
// Create a new Blob and write it to log.txt.
var blob = new Blob([someText], {type: 'text/plain'});
fileWriter.write(blob);
}, errorHandler);
}, errorHandler);
}
function errorHandler(e){
var msg = '';
switch (e.code){
case FileError.QUOTA_EXCEEDED_ERR:
msg = 'QUOTA_EXCEEDED_ERR';
break;
case FileError.NOT_FOUND_ERR:
msg = 'NOT_FOUND_ERR';
break;
case FileError.SECURITY_ERR:
msg = 'SECURITY_ERR';
break;
case FileError.INVALID_MODIFICATION_ERR:
msg = 'INVALID_MODIFICATION_ERR';
break;
case FileError.INVALID_STATE_ERR:
msg = 'INVALID_STATE_ERR';
break;
default:
msg = 'Unknown Error';
break;
};
alert('Error: ' + msg);
}
setTimeout(function clearFile(){
window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, onClearInitFs, errorHandler);
}, 1000);
setTimeout(function writeToFile(){
window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, onWriteInitFs, errorHandler);
}, 3000);
</script>
</head>
<body>
</body>
</html>