Skip to content

Commit

Permalink
Catche error 99 and returns original buffer (#33)
Browse files Browse the repository at this point in the history
fix #32
  • Loading branch information
davidfig authored and shinnn committed Jan 25, 2017
1 parent 6c3631e commit b889812
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Binary file added fixture-no-compress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ module.exports = opts => buf => {
bin: pngquant,
args
}).catch(err => {
if (err.code === 99) {
return buf;
}
err.message = err.stderr || err.message;
throw err;
});
Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ test('throw on corrupt image', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixture-corrupt.png'));
t.throws(m()(buf), /PNG file corrupted/);
});

test('skip optimizing a fully optimized PNG', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixture-no-compress.png'));
const data = await m({quality: 100})(buf);
t.is(data.length, buf.length);
t.true(isPng(data));
});

0 comments on commit b889812

Please sign in to comment.