Allow use of toBuffer+toFile w/ same instance #3044

This commit is contained in:
Lovell Fuller 2022-02-03 22:01:46 +00:00
parent 2b01951306
commit 424660278d
3 changed files with 18 additions and 0 deletions

View File

@ -6,6 +6,9 @@ Requires libvips v8.12.2
### v0.30.1 - TBD
* Allow use of `toBuffer` and `toFile` on the same instance.
[#3044](https://github.com/lovell/sharp/issues/3044)
* Skip shrink-on-load for known libjpeg rounding errors.
[#3066](https://github.com/lovell/sharp/issues/3066)

View File

@ -139,6 +139,7 @@ function toBuffer (options, callback) {
} else if (this.options.resolveWithObject) {
this.options.resolveWithObject = false;
}
this.options.fileOut = '';
return this._pipeline(is.fn(options) ? options : callback);
}

View File

@ -328,6 +328,20 @@ describe('Input/output', function () {
});
});
it('Allow use of toBuffer and toFile with same instance', async () => {
const instance = sharp({
create: {
width: 8,
height: 8,
channels: 3,
background: 'red'
}
});
await instance.toFile(fixtures.path('output.jpg'));
const data = await instance.toBuffer();
assert.strictEqual(Buffer.isBuffer(data), true);
});
it('Fail when output File is input File', function (done) {
sharp(fixtures.inputJpg).toFile(fixtures.inputJpg, function (err) {
assert(err instanceof Error);