-
Notifications
You must be signed in to change notification settings - Fork 23
/
compress.js
29 lines (26 loc) · 971 Bytes
/
compress.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 adapter() {
try {
var zlib = require('zlib');
if (zlib.hasOwnProperty('brotliCompress')) {
return zlib.brotliCompress;
}
} catch (err) {}
try {
console.log('warning: couldn\'t find native brotli support in zlib library. trying to fall back to iltorb.');
var iltorb = require('iltorb');
return iltorb.compress;
} catch (err) {
console.log('warning: couldn\'t load iltorb library. trying to fall back to brotli.js.');
console.log(err);
try {
var brotli = require('brotli');
return function (content, options, callback) {
var result = brotli.compress(content, options);
callback(null, result);
}
} catch (err) {
throw new Error('iltorb or brotli not found. See https://github.com/mynameiswhm/brotli-webpack-plugin for details.');
}
}
}
module.exports = adapter;