Fail fast when input Buffer is empty #37

This commit is contained in:
Lovell Fuller 2014-06-02 21:11:25 +01:00
parent 7319533969
commit 46b701c85c
2 changed files with 18 additions and 5 deletions

View File

@ -24,7 +24,11 @@ var Sharp = function(input) {
if (typeof input === 'string') {
this.options.fileIn = input;
} else if (typeof input ==='object' && input instanceof Buffer) {
if (input.length > 0) {
this.options.bufferIn = input;
} else {
throw 'Buffer is empty';
}
} else {
throw 'Unsupported input ' + typeof input;
}

View File

@ -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();
}
]);