Skip to content

Commit 11ff6f5

Browse files
committed
Add HTTP fallback mechanism
1 parent f1c3bc4 commit 11ff6f5

File tree

18 files changed

+195
-10
lines changed

18 files changed

+195
-10
lines changed

karma.conf.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,19 @@ module.exports = function (config) {
2121
frameworks: ['jasmine'],
2222
// list of files / patterns to load in the browser
2323
files: [
24-
'src/**/*.spec.js'
24+
'src/**/*.spec.js',
25+
{
26+
pattern: 'src/__tests__/__fixtures__/test-folder/**/*',
27+
served: true,
28+
watched: false,
29+
included: false
30+
},
31+
{
32+
pattern: 'src/__tests__/__fixtures__/test-folder/**/.*',
33+
served: true,
34+
watched: false,
35+
included: false
36+
},
2537
],
2638
// list of files to exclude
2739
// exclude: [

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"version": "0.0.0",
77
"description": "A lean and fast 'fs' for the browser",
88
"main": "index.js",
9+
"bin": {
10+
"superblocktxt": "src/superblocktxt.js"
11+
},
912
"scripts": {
1013
"test": "karma start --single-run"
1114
},

src/CacheFS.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ module.exports = class CacheFS {
88
const root = this._makeRoot();
99
this._root = new Map([["/", root]]);
1010
}
11-
_makeRoot() {
12-
let root = new Map();
11+
_makeRoot(root) {
12+
root = root || new Map();
1313
let stat = { mode: 0o777, type: "dir", size: 0, mtimeMs: Date.now() };
1414
root.set(STAT, stat);
1515
return root
1616
}
17+
loadSuperBlock(superblock) {
18+
if (typeof superblock === 'string') {
19+
let root = this.parse(superblock)
20+
root = this._makeRoot(root);
21+
this._root = new Map([["/", root]]);
22+
} else {
23+
this._root = superblock
24+
}
25+
}
1726
print(root) {
1827
root = root || this._root.get("/")
1928
let str = "";
@@ -33,7 +42,7 @@ module.exports = class CacheFS {
3342
}
3443
};
3544
printTree(root, 0);
36-
return str.trimStart();
45+
return str.trimStart() + '\n';
3746
}
3847
parse(print) {
3948
function mk(stat) {

src/HttpBackend.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = class IdbBackend {
2+
constructor(url) {
3+
this._url = url;
4+
}
5+
loadSuperblock() {
6+
return fetch(this._url + '/.superblock.txt').then(res => res.text())
7+
}
8+
readFile(filepath) {
9+
return fetch(this._url + filepath).then(res => res.arrayBuffer())
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
0 40755
2+
a.txt 100644 14 1545621303427.1333
3+
b.txt 100644 14 1545621303427.2192
4+
c.txt 100644 14 1545621303427.2607
5+
1 40755
6+
d.txt 100644 14 1545621340683.4724
7+
e.txt 100644 14 1545621349775.4539
8+
f.txt 100644 14 1545621356008.1582
9+
a.txt 100644 14 1545621375109
10+
b.txt 100644 14 1545621255760.9512
11+
c.txt 100644 14 1545621290070.7742
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello from "a"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello from "b"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello from "c"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello from "d"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello from "e"

0 commit comments

Comments
 (0)