diff --git a/index.js b/index.js index b59d06a6..4f10a9a3 100755 --- a/index.js +++ b/index.js @@ -24,7 +24,11 @@ var Sharp = function(input) { if (typeof input === 'string') { this.options.fileIn = input; } else if (typeof input ==='object' && input instanceof Buffer) { - this.options.bufferIn = input; + if (input.length > 0) { + this.options.bufferIn = input; + } else { + throw 'Buffer is empty'; + } } else { throw 'Unsupported input ' + typeof input; } diff --git a/tests/unit.js b/tests/unit.js index 1b396b6b..51a0efc7 100755 --- a/tests/unit.js +++ b/tests/unit.js @@ -209,12 +209,12 @@ async.series([ }, // Rotate to an invalid angle, should fail function(done) { - var isValid = false; + var fail = false; try { sharp(inputJpg).rotate(1); - isValid = true; + fail = true; } catch (e) {} - assert(!isValid); + assert(!fail); done(); }, // Do not enlarge the output if the input width is already less than the output width @@ -252,6 +252,15 @@ async.series([ }).catch(function(err) { throw err; }); + }, + // Empty Buffer, should fail + function(done) { + var fail = false; + try { + sharp(new Buffer(0)); + fail = true; + } catch (e) {} + assert(!fail); + done(); } - ]);