-
Notifications
You must be signed in to change notification settings - Fork 12
/
worker.js
executable file
·60 lines (46 loc) · 1 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var Module = {
'noInitialRun' : true,
'noFSInit' : true
};
importScripts('pngcrush.js');
var line = '';
Module.preRun = function() {
FS.init(function() {
return null;
}, function(data) {
if(data == 10) {
postMessage({
'type' : 'stdout',
'line' : line
});
line = '';
} else {
line += String.fromCharCode(data);
}
});
};
function getFileData(fileName) {
var data = FS.root.contents[fileName].contents;
return new Uint8Array(data).buffer;
};
onmessage = function(event) {
var message = event.data;
switch(message.type) {
case "file":
FS.createDataFile('/', 'input.png', message.data, true, false);
break;
case "command":
if(message.command == "go") {
postMessage({'type' : 'start'});
Module.run(['-reduce', '-rem', 'alla', '-rem', 'text', 'input.png', 'output.png']);
postMessage({
'type' : 'done',
'data' : getFileData('output.png')
});
}
break;
};
};
postMessage({
'type' : 'ready'
});