-
Notifications
You must be signed in to change notification settings - Fork 11
/
lfs_js_bd.js
51 lines (43 loc) · 1.13 KB
/
lfs_js_bd.js
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
// block device class
function BD(read_size, prog_size, erase_size, size) {
this.read_size = read_size
this.prog_size = prog_size
this.erase_size = erase_size
this.size = size
this._storage = []
}
BD.prototype.read = function(block, off, buffer, size) {
if (this.onread) {
if (this.onread(block, off, size) == false) {
return 0
}
}
if (!this._storage[block]) {
this._storage[block] = new Uint8Array(this.erase_size);
}
Module.HEAPU8.set(
new Uint8Array(this._storage[block].buffer, off, size),
buffer)
return 0
}
BD.prototype.prog = function(block, off, buffer, size) {
if (this.onprog) {
if (this.onprog(block, off, size) == false) {
return 0
}
}
if (!this._storage[block]) {
this._storage[block] = new Uint8Array(this.erase_size);
}
this._storage[block].set(
new Uint8Array(Module.HEAPU8.buffer, buffer, size),
off)
return 0
}
BD.prototype.erase = function(block) {
if (this.onerase) {
this.onerase(block)
}
delete this._storage[block]
return 0
}