Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 53ec8a9

Browse files
Icehunterjoshwiens
authored andcommitted
fix: TypeError Invalid non-strig/buffer chunk
1 parent d26fd7b commit 53ec8a9

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

index.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,38 @@ function CompressionPlugin(options) {
1111
options = options || {};
1212
this.asset = options.asset || "[path].gz[query]";
1313
this.algorithm = options.algorithm || "gzip";
14+
this.compressionOptions = {};
1415
if(typeof this.algorithm === "string") {
1516
if (this.algorithm === "zopfli") {
1617
try {
1718
var zopfli = require("node-zopfli");
1819
} catch(err) {
1920
throw new Error("node-zopfli not found");
2021
}
21-
this.algorithm = function (content, fn) {
22-
zopfli.gzip(content, {
23-
verbose: options.hasOwnProperty('verbose') ? options.verbose : false,
24-
verbose_more: options.hasOwnProperty('verbose_more') ? options.verbose_more : false,
25-
numiterations: options.numiterations ? options.numiterations : 15,
26-
blocksplitting: options.hasOwnProperty('blocksplitting') ? options.blocksplitting : true,
27-
blocksplittinglast: options.hasOwnProperty('blocksplittinglast') ? options.blocksplittinglast : false,
28-
blocksplittingmax: options.blocksplittingmax ? options.blocksplittingmax : 15
29-
}, fn);
22+
this.compressionOptions = {
23+
verbose: options.hasOwnProperty('verbose') ? options.verbose : false,
24+
verbose_more: options.hasOwnProperty('verbose_more') ? options.verbose_more : false,
25+
numiterations: options.numiterations ? options.numiterations : 15,
26+
blocksplitting: options.hasOwnProperty('blocksplitting') ? options.blocksplitting : true,
27+
blocksplittinglast: options.hasOwnProperty('blocksplittinglast') ? options.blocksplittinglast : false,
28+
blocksplittingmax: options.blocksplittingmax ? options.blocksplittingmax : 15
29+
};
30+
this.algorithm = function (content, options, fn) {
31+
zopfli.gzip(content, options, fn);
3032
};
3133
} else {
3234
var zlib = require("zlib");
3335
this.algorithm = zlib[this.algorithm];
3436
if(!this.algorithm) throw new Error("Algorithm not found in zlib");
35-
this.algorithm = this.algorithm.bind(zlib, {
37+
this.compressionOptions = {
3638
level: options.level || 9,
3739
flush: options.flush,
3840
chunkSize: options.chunkSize,
3941
windowBits: options.windowBits,
4042
memLevel: options.memLevel,
4143
strategy: options.strategy,
4244
dictionary: options.dictionary
43-
});
45+
};
4446
}
4547
}
4648
this.test = options.test || options.regExp;
@@ -65,7 +67,7 @@ CompressionPlugin.prototype.apply = function(compiler) {
6567
content = new Buffer(content, "utf-8");
6668
var originalSize = content.length;
6769
if(originalSize < this.threshold) return callback();
68-
this.algorithm(content, function(err, result) {
70+
this.algorithm(content, this.compressionOptions, function(err, result) {
6971
if(err) return callback(err);
7072
if(result.length / originalSize > this.minRatio) return callback();
7173
var parse = url.parse(file);

0 commit comments

Comments
 (0)