-
-
Notifications
You must be signed in to change notification settings - Fork 168
/
worker.js
29 lines (27 loc) · 1.01 KB
/
worker.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
;(function(root) {
"use strict";
root.onmessage = function(e) {
var _chunk = e.data.f.slice(e.data.cs * (e.data.cc - 1), e.data.cs * e.data.cc);
if (e.data.ib === true) {
postMessage({bin: _chunk, chunkId: e.data.cc});
} else {
var fileReader;
if (root.FileReader) {
fileReader = new FileReader();
fileReader.onloadend = function(chunk) {
postMessage({bin: (fileReader.result || chunk.srcElement || chunk.target).split(',')[1], chunkId: e.data.cc, s: e.data.s});
};
fileReader.onerror = function(error) {
throw (error.target || error.srcElement).error;
};
fileReader.readAsDataURL(_chunk);
} else if (root.FileReaderSync) {
fileReader = new FileReaderSync();
postMessage({bin: fileReader.readAsDataURL(_chunk).split(',')[1], chunkId: e.data.cc});
} else {
postMessage({bin: null, chunkId: e.data.cc, error: 'File API is not supported in WebWorker!'});
}
}
return;
};
}(this));