forked from veliovgroup/Meteor-Files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
28 lines (24 loc) · 1.03 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
"use strict";
self.onmessage = function(e) {
if (e.data.ib === true) {
postMessage({bin: e.data.f.slice(e.data.cs * (e.data.cc - 1), e.data.cs * e.data.cc), chunkId: e.data.cc});
} else {
var fileReader;
if (self.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(e.data.f.slice(e.data.cs * (e.data.cc - 1), e.data.cs * e.data.cc));
} else if (self.FileReaderSync) {
fileReader = new FileReaderSync();
postMessage({bin: fileReader.readAsDataURL(e.data.f.slice(e.data.cs * (e.data.cc - 1), e.data.cs * e.data.cc)).split(',')[1], chunkId: e.data.cc});
} else {
postMessage({bin: null, chunkId: e.data.cc, error: 'File API is not supported in WebWorker!'});
}
}
return;
};