Skip to content
This repository was archived by the owner on Jan 24, 2020. It is now read-only.

Commit be07b6c

Browse files
author
Avaer Kazmer
committed
Add new localForage initialization
1 parent 10a227a commit be07b6c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

index.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,58 @@
9898
}
9999
const query = parseQuery(window.location.search); */
100100

101+
localforage.config({driver: localforage.INDEXEDDB});
102+
const chunkSize = 100 * 1024 * 1024;
103+
localforage.write = (p, d) => new Promise((accept, reject) => {
104+
console.log('write', p, d);
105+
const _recurse = (startIndex = 0, index = 0) => {
106+
if (startIndex < d.length) {
107+
const slice = d.slice(startIndex, startIndex + chunkSize);
108+
109+
console.log('set item', p + '-' + index);
110+
localforage.setItem(p + '-' + index, slice, err => {
111+
if (!err) {
112+
startIndex += slice.length;
113+
index++;
114+
_recurse(startIndex, index);
115+
} else {
116+
reject(err);
117+
}
118+
});
119+
} else {
120+
localforage.removeItem(p + '-' + index, err => {
121+
if (!err) {
122+
accept();
123+
} else {
124+
reject(err);
125+
}
126+
});
127+
}
128+
};
129+
_recurse();
130+
});
131+
localforage.read = p => new Promise((accept, reject) => {
132+
const result = [];
133+
const _recurse = (index = 0) => {
134+
console.log('get item', p + '-' + index);
135+
localforage.getItem(p + '-' + index, (err, data) => {
136+
if (!err) {
137+
if (data) {
138+
result.push(data);
139+
140+
index++;
141+
_recurse(index);
142+
} else {
143+
accept(result);
144+
}
145+
} else {
146+
reject(err);
147+
}
148+
});
149+
};
150+
_recurse();
151+
});
152+
101153
// helpers
102154

103155
const _getFrontOfCamera = () => {

0 commit comments

Comments
 (0)