Prevent writing output file over input file - closes #28

This commit is contained in:
Lovell Fuller 2014-05-22 22:27:02 +01:00
parent 6c96bd0d37
commit e32faac17a
2 changed files with 13 additions and 2 deletions

View File

@ -107,9 +107,13 @@ Sharp.prototype.resize = function(width, height) {
Sharp.prototype.write = function(output, callback) {
if (!output || output.length === 0) {
throw 'Invalid output';
callback('Invalid output');
} else {
this._sharp(output, callback);
if (this.options.inFile === output) {
callback('Cannot use same file for input and output');
} else {
this._sharp(output, callback);
}
}
return this;
};

View File

@ -145,5 +145,12 @@ async.series([
done();
});
});
},
// Attempt to output to input, should fail
function(done) {
sharp(inputJpg).write(inputJpg, function(err) {
assert(!!err);
done();
});
}
]);