mirror of
https://github.com/remy/inliner.git
synced 2024-09-11 17:25:30 +03:00
make gzip support optional for command line use
This commit is contained in:
parent
4dcafce31e
commit
da3311cb54
35
inliner.js
35
inliner.js
@ -5,7 +5,7 @@ var URL = require('url'),
|
||||
jsdom = require('jsdom'),
|
||||
jsp = require('uglify-js/lib/parse-js'),
|
||||
pro = require('uglify-js/lib/process'),
|
||||
compress = require('./node-compress/lib/compress/'),
|
||||
compress = null, // import only when required - might make the command line tool easier to use
|
||||
http = {
|
||||
http: require('http'),
|
||||
https: require('https')
|
||||
@ -25,31 +25,6 @@ function makeRequest(url) {
|
||||
return http[oURL.protocol.slice(0, -1) || 'http'].request(options);
|
||||
}
|
||||
|
||||
function decompress(input, callback) {
|
||||
var decompressor = new compress.GunzipStream();
|
||||
console.log(input.toString());
|
||||
// var d1 = input.substr(0, 25);
|
||||
// var d2 = input.substr(25);
|
||||
|
||||
console.log('Making decompression requests...');
|
||||
var output = '';
|
||||
// decompressor.setInputEncoding('binary');
|
||||
decompressor.setEncoding('utf8');
|
||||
decompressor.addListener('data', function(data) {
|
||||
output += data;
|
||||
}).addListener('error', function(err) {
|
||||
throw err;
|
||||
}).addListener('end', function() {
|
||||
console.log('Decompressed length: ' + output.length);
|
||||
console.log('Raw data: ' + output);
|
||||
callback(output);
|
||||
});
|
||||
// decompressor.write(d1);
|
||||
decompressor.write(input);
|
||||
decompressor.close();
|
||||
console.log('Requests done.');
|
||||
}
|
||||
|
||||
function compressCSS(css) {
|
||||
return css
|
||||
.replace(/\s+/g, ' ')
|
||||
@ -330,6 +305,14 @@ Inliner.prototype.get = function (url, options, callback) {
|
||||
var gunzip;
|
||||
|
||||
if (res.headers['content-encoding'] == 'gzip') {
|
||||
if (compress === null) {
|
||||
try {
|
||||
compress = require('./node-compress/lib/compress/');
|
||||
} catch (e) {
|
||||
console.error('Cannot request gzipped content without node-compress library - exiting');
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
gunzip = new compress.GunzipStream();
|
||||
gunzip.on('data', function (chunk) {
|
||||
body += chunk;
|
||||
|
Loading…
Reference in New Issue
Block a user