mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Allow instance reuse with differing toBuffer options (#1860)
This commit is contained in:
parent
69fe21a7ec
commit
fb5c393fbd
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@ vendor
|
|||||||
.nyc_output
|
.nyc_output
|
||||||
.vscode/
|
.vscode/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
.idea
|
||||||
|
@ -92,6 +92,8 @@ function toFile (fileOut, callback) {
|
|||||||
function toBuffer (options, callback) {
|
function toBuffer (options, callback) {
|
||||||
if (is.object(options)) {
|
if (is.object(options)) {
|
||||||
this._setBooleanOption('resolveWithObject', options.resolveWithObject);
|
this._setBooleanOption('resolveWithObject', options.resolveWithObject);
|
||||||
|
} else if (this.options.resolveWithObject) {
|
||||||
|
this.options.resolveWithObject = false;
|
||||||
}
|
}
|
||||||
return this._pipeline(is.fn(options) ? options : callback);
|
return this._pipeline(is.fn(options) ? options : callback);
|
||||||
}
|
}
|
||||||
|
19
test/unit/toBuffer.js
Normal file
19
test/unit/toBuffer.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const sharp = require('../../');
|
||||||
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
|
describe('toBuffer', () => {
|
||||||
|
it('reusing same sharp object does not reset previously passed parameters to toBuffer', (done) => {
|
||||||
|
let image = sharp(fixtures.inputJpg);
|
||||||
|
image.toBuffer({ resolveWithObject: true }).then((obj) => {
|
||||||
|
image.toBuffer().then((buff) => {
|
||||||
|
assert.strict.equal(Buffer.isBuffer(buff), true);
|
||||||
|
assert.strict.equal(typeof obj, 'object');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user