-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
46 lines (40 loc) · 1.54 KB
/
index.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>API test</title>
<meta name="description" content="API tester">
<meta name="author" content="robot">
</head>
<body>
<iframe id="frame"></iframe>
<script type="module">
import SimpleFS from "/dist/SimpleFS.mjs"
const fs = new SimpleFS.FileSystem()
function readFile() {
fs.readFile('abc/test.html').then((data) => {
// data is blob
console.log(data);
var url = URL.createObjectURL(data);
console.log('blob url: ' + url);
var frame = document.getElementById('frame');
frame.setAttribute('src', url);
// create file reader and read blob
var fr = new FileReader();
fr.onload = function() {
console.log(fr.result);
}
fr.readAsText(data);
})
}
fs.mkdir('abc') // creates abc folder
.then(() => fs.mkdir('abc/def')) // adds def folder to abc
.then(() => fs.rmdir('abc/def')) // removes def folder
.then(() => fs.writeFile('abc/theme.css', new Blob(['h1 { color: green }'], {type: 'text/css'})))
.then(() => fs.writeFile('abc/test.html', new Blob(['<html><head><link rel="stylesheet" type="text/css" href="abc/theme.css"></head><body><h1>Bloby</h1><img src="https://res.cloudinary.com/forlagshuset/image/upload/v1520845867/FBF_banner_spring_fpa5e3bd2o.jpg"></body></html>'], {type:'text/html'})))
.then(() => readFile())
.then(() => fs.unlink('abc/test.html'))
.catch((e) => {console.error(e)})
</script>
</body>
</html>