mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Prevent writing output file over input file - closes #28
This commit is contained in:
parent
6c96bd0d37
commit
e32faac17a
6
index.js
6
index.js
@ -107,10 +107,14 @@ Sharp.prototype.resize = function(width, height) {
|
|||||||
|
|
||||||
Sharp.prototype.write = function(output, callback) {
|
Sharp.prototype.write = function(output, callback) {
|
||||||
if (!output || output.length === 0) {
|
if (!output || output.length === 0) {
|
||||||
throw 'Invalid output';
|
callback('Invalid output');
|
||||||
|
} else {
|
||||||
|
if (this.options.inFile === output) {
|
||||||
|
callback('Cannot use same file for input and output');
|
||||||
} else {
|
} else {
|
||||||
this._sharp(output, callback);
|
this._sharp(output, callback);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -145,5 +145,12 @@ async.series([
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
// Attempt to output to input, should fail
|
||||||
|
function(done) {
|
||||||
|
sharp(inputJpg).write(inputJpg, function(err) {
|
||||||
|
assert(!!err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user