@polyfill-io-aot/builder
Version:
This is the builder module for polyfill-io-aot.
41 lines • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs-extra");
const zopfli = require("node-zopfli-es");
const wp = require("workerpool");
const zlib_1 = require("zlib");
const resolveSourcePath = require("./util/resolveSourcePath");
function write(path) {
return (outBuf) => fs.writeFile(path, outBuf);
}
/** @internal */
function gzip(root, hash, opts) {
const path = resolveSourcePath(root, hash);
const out = `${path}.gz`;
return fs.readFile(path)
.then((sourceBuf) => zopfli.gzip(sourceBuf, opts))
.then(write(out));
}
exports.gzip = gzip;
/** @internal */
function brotli(root, hash, opts) {
const path = resolveSourcePath(root, hash);
const out = `${path}.br`;
return fs.readFile(path)
.then((sourceBuf) => new Promise((resolve, reject) => {
zlib_1.brotliCompress(sourceBuf, { params: opts }, (error, result) => {
if (error) {
reject(error);
}
else {
resolve(result);
}
});
}))
.then(write(out));
}
exports.brotli = brotli;
if (!wp.isMainThread) {
wp.worker({ brotli, gzip });
}
//# sourceMappingURL=compress.js.map