<commit_before>var async = require('async'),
    _ = require('underscore'),
    AssetGraph = require('../AssetGraph');

var compress;

try {
    compress = require('node-zopfli');
} catch (e) {
    console.warn('node-zopfli is not available, using less efficient zlib compression');
    compress = require('zlib');
}

module.exports = function (queryObj) {
    return function gzip(assetGraph, cb) {
        async.eachLimit(assetGraph.findAssets(_.extend({isInline: false}, queryObj)), 4, function (asset, cb) {

            // http://webmasters.stackexchange.com/questions/31750/what-is-recommended-minimum-object-size-for-gzip-performance-benefits
            if (asset.rawSrc.length <= 860) {
                return cb();
            }

            compress.gzip(asset.rawSrc, function (err, gzippedRawSrc) {
                if (err) {<commit_msg>Only require gzip libraries if there are assets to compress.<commit_after>var async = require('async'),
    _ = require('underscore'),
    AssetGraph = require('../AssetGraph');

module.exports = function (queryObj) {
    return function gzip(assetGraph, cb) {
        var compress,
            gzipAssets = assetGraph.findAssets(_.extend({isInline: false}, queryObj));

        if (gzipAssets.length > 0) {
          try {
            compress = require('node-zopfli');
          } catch (e) {
            assetGraph.emit('info', new Error('node-zopfli is not available, using less efficient zlib compression'));
            compress = require('zlib');
          }
        }

        async.eachLimit(gzipAssets, 4, function (asset, cb) {
            // http://webmasters.stackexchange.com/questions/31750/what-is-recommended-minimum-object-size-for-gzip-performance-benefits
            if (asset.rawSrc.length <= 860) {
                return cb();
            }

            compress.gzip(asset.rawSrc, function (err, gzippedRawSrc) {
                if (err) {
{'fraction_non_alphanumeric': 0.13270637408568442, 'fraction_numerical': 0.009926854754440962, 'mean_word_length': 2.4945255474452557, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3705462', 'n_tokens_mistral': 592, 'n_tokens_neox': 553, 'n_words': 116}