Total Complexity | 8 |
Complexity/F | 1 |
Lines of Code | 45 |
Function Count | 8 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /** |
||
17 | const fileBytesReader = function(file) { |
||
1 ignored issue
–
show
|
|||
18 | let _i = 0; |
||
19 | let _fileSize = file.size; |
||
20 | let _reader = new FileReader(); |
||
21 | let _file = file; |
||
22 | |||
23 | function readChunk(length) { |
||
24 | return new Promise((resolve, reject) => { |
||
25 | let blob = _file.slice(_i, _i += length); |
||
26 | |||
27 | _reader.onload = () => { |
||
28 | // return Uint8Array |
||
29 | resolve(new Uint8Array(_reader.result)); |
||
30 | }; |
||
31 | |||
32 | _reader.onerror = reject; |
||
33 | |||
34 | _reader.readAsArrayBuffer(blob); |
||
35 | }); |
||
36 | } |
||
37 | |||
38 | async function readBytes(length) { |
||
39 | return await readChunk(length); |
||
40 | } |
||
41 | |||
42 | async function readByte() { |
||
43 | let bytes = await readBytes(1); |
||
44 | return bytes[0]; |
||
45 | } |
||
46 | |||
47 | function getCurrentPosition() { |
||
48 | return _i; |
||
49 | } |
||
50 | |||
51 | function getLength() { |
||
52 | return _fileSize; |
||
53 | } |
||
54 | |||
55 | return { |
||
56 | readByte: readByte, |
||
57 | readBytes: readBytes, |
||
58 | getCurrentPosition: getCurrentPosition, |
||
59 | getLength: getLength, |
||
60 | }; |
||
61 | }; |
||
62 |