imagemin-advpng
Advanced tools
Comparing version 2.0.0 to 2.1.0
93
index.js
@@ -11,3 +11,51 @@ 'use strict'; | ||
* | ||
* @param {Object} file | ||
* @param {String} enc | ||
* @param {Object} opts | ||
* @param {Function} cb | ||
* @api private | ||
*/ | ||
function plugin(file, enc, opts, cb) { | ||
if (file.isNull()) { | ||
cb(null, file); | ||
return; | ||
} | ||
if (file.isStream()) { | ||
cb(new Error('Streaming is not supported')); | ||
return; | ||
} | ||
if (!isPng(file.contents)) { | ||
cb(null, file); | ||
return; | ||
} | ||
var exec = new ExecBuffer(); | ||
var args = ['--recompress', '-q']; | ||
var optimizationLevel = opts.optimizationLevel || 3; | ||
if (typeof optimizationLevel === 'number') { | ||
args.push('-' + optimizationLevel); | ||
} | ||
exec | ||
.dest(exec.src()) | ||
.use(advpng, args.concat([exec.src()])) | ||
.run(file.contents, function (err, buf) { | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
file.contents = buf; | ||
cb(null, file); | ||
}); | ||
} | ||
/** | ||
* Module exports | ||
* | ||
* @param {Object} opts | ||
* @api public | ||
@@ -20,38 +68,19 @@ */ | ||
return through.obj(function (file, enc, cb) { | ||
if (file.isNull()) { | ||
cb(null, file); | ||
return; | ||
} | ||
plugin(file, enc, opts, cb); | ||
}); | ||
}; | ||
if (file.isStream()) { | ||
cb(new Error('Streaming is not supported')); | ||
return; | ||
} | ||
/** | ||
* Module exports constructor | ||
* | ||
* @param {Object} opts | ||
* @api public | ||
*/ | ||
if (!isPng(file.contents)) { | ||
cb(null, file); | ||
return; | ||
} | ||
module.exports.ctor = function (opts) { | ||
opts = opts || {}; | ||
var exec = new ExecBuffer(); | ||
var args = ['--recompress', '-q']; | ||
var optimizationLevel = opts.optimizationLevel || 3; | ||
if (typeof optimizationLevel === 'number') { | ||
args.push('-' + optimizationLevel); | ||
} | ||
exec | ||
.dest(exec.src()) | ||
.use(advpng, args.concat([exec.src()])) | ||
.run(file.contents, function (err, buf) { | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
file.contents = buf; | ||
cb(null, file); | ||
}); | ||
return through.ctor({ objectMode: true }, function (file, enc, cb) { | ||
plugin(file, enc, opts, cb); | ||
}); | ||
}; |
{ | ||
"name": "imagemin-advpng", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "advpng imagemin plugin", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3578
69