-
Notifications
You must be signed in to change notification settings - Fork 6
/
pre.js
44 lines (37 loc) · 1003 Bytes
/
pre.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
module.exports = function(file, options) {
// file: Typed array containing file in PPM, PGM, BMP, or Targa format.
// options: hash containing options to pass to cjpeg or an array of arguments
// returns: object, data = typed array with file output, stderr = command output
var stdout = "";
var stderr = "";
var args = ["-outfile", "/output.jpg"];
if (Array.isArray(options)) {
args = args.concat(options);
} else {
for (var key in options) {
if (!options.hasOwnProperty(key)) continue;
if (options[key]) {
args.push("-" + key);
if (typeof options[key] !== "boolean") {
// option has a value
args.push(String(options[key]));
}
}
}
}
args.push("/input");
var Module = {
"print": function(text) {
stdout += text;
},
"printErr": function(text) {
stderr += text;
},
"preRun": [function() {
FS.writeFile("/input", file, {
encoding: "binary"
});
}],
"arguments": args,
"ENVIRONMENT": "SHELL" // maximum compatibility?
};