mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Fail fast when input Buffer is empty #37
This commit is contained in:
parent
7319533969
commit
46b701c85c
6
index.js
6
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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user