From 29dba17c29e3ed86394155c544d615205274bfee Mon Sep 17 00:00:00 2001 From: Felix Schoeler Date: Tue, 19 Jul 2016 16:06:31 +0200 Subject: [PATCH 1/5] Added possibility to set binary path of pngquant manually --- lib/PngQuant.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/PngQuant.js b/lib/PngQuant.js index e285797..c583aae 100644 --- a/lib/PngQuant.js +++ b/lib/PngQuant.js @@ -22,6 +22,11 @@ function PngQuant(pngQuantArgs) { util.inherits(PngQuant, Stream); PngQuant.getBinaryPath = memoizeAsync(function (cb) { + if(this.binaryPath !== undefined) { + cb(this.binaryPath); + return; + } + which('pngquant', function (err, pngQuantBinaryPath) { if (err) { pngQuantBinaryPath = require('pngquant-bin'); @@ -34,6 +39,10 @@ PngQuant.getBinaryPath = memoizeAsync(function (cb) { }); }); +PngQuant.setBinaryPath = function(binaryPath) { + this.binaryPath = binaryPath; +}; + PngQuant.prototype._error = function (err) { if (!this.hasEnded) { this.hasEnded = true; From 24bffa409c9439182eb7550125c7959509d17048 Mon Sep 17 00:00:00 2001 From: Felix Schoeler Date: Tue, 19 Jul 2016 16:52:13 +0200 Subject: [PATCH 2/5] Fixed wrong callback parameters --- lib/PngQuant.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/PngQuant.js b/lib/PngQuant.js index c583aae..ca8e2cb 100644 --- a/lib/PngQuant.js +++ b/lib/PngQuant.js @@ -23,7 +23,7 @@ util.inherits(PngQuant, Stream); PngQuant.getBinaryPath = memoizeAsync(function (cb) { if(this.binaryPath !== undefined) { - cb(this.binaryPath); + cb(null, this.binaryPath); return; } From a0dcc76c2cf880a84b8c67c5f69677f964203a19 Mon Sep 17 00:00:00 2001 From: Felix Schoeler Date: Tue, 19 Jul 2016 16:54:09 +0200 Subject: [PATCH 3/5] Fixed immediate calling of callback --- lib/PngQuant.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/PngQuant.js b/lib/PngQuant.js index ca8e2cb..8912ff5 100644 --- a/lib/PngQuant.js +++ b/lib/PngQuant.js @@ -23,7 +23,9 @@ util.inherits(PngQuant, Stream); PngQuant.getBinaryPath = memoizeAsync(function (cb) { if(this.binaryPath !== undefined) { - cb(null, this.binaryPath); + setTimeout(function() { + cb(null, this.binaryPath); + }, 0); return; } From d784d08d31b2fad9bd59b2aca7ae3e86a6bc43fd Mon Sep 17 00:00:00 2001 From: Felix Schoeler Date: Tue, 19 Jul 2016 17:07:05 +0200 Subject: [PATCH 4/5] Replaced setTimeout with setImmediate --- lib/PngQuant.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/PngQuant.js b/lib/PngQuant.js index 8912ff5..7190131 100644 --- a/lib/PngQuant.js +++ b/lib/PngQuant.js @@ -23,9 +23,9 @@ util.inherits(PngQuant, Stream); PngQuant.getBinaryPath = memoizeAsync(function (cb) { if(this.binaryPath !== undefined) { - setTimeout(function() { + setImmediate(function() { cb(null, this.binaryPath); - }, 0); + }); return; } From 472bb84b833377f080495a1700de42355053e62a Mon Sep 17 00:00:00 2001 From: Felix Schoeler Date: Tue, 19 Jul 2016 17:15:27 +0200 Subject: [PATCH 5/5] Set the JSHint environment to NodeJS to make tests pass --- lib/PngQuant.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/PngQuant.js b/lib/PngQuant.js index 7190131..a675a9e 100644 --- a/lib/PngQuant.js +++ b/lib/PngQuant.js @@ -1,3 +1,4 @@ +/*jshint node: true */ var childProcess = require('child_process'), Stream = require('stream').Stream, util = require('util'),