Skip to content

Commit fb5c393

Browse files
RaboliotLeGrislovell
authored andcommitted
Allow instance reuse with differing toBuffer options (lovell#1860)
1 parent 69fe21a commit fb5c393

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ vendor
1414
.nyc_output
1515
.vscode/
1616
package-lock.json
17+
.idea

lib/output.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ function toFile (fileOut, callback) {
9292
function toBuffer (options, callback) {
9393
if (is.object(options)) {
9494
this._setBooleanOption('resolveWithObject', options.resolveWithObject);
95+
} else if (this.options.resolveWithObject) {
96+
this.options.resolveWithObject = false;
9597
}
9698
return this._pipeline(is.fn(options) ? options : callback);
9799
}

test/unit/toBuffer.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
5+
const sharp = require('../../');
6+
const fixtures = require('../fixtures');
7+
8+
describe('toBuffer', () => {
9+
it('reusing same sharp object does not reset previously passed parameters to toBuffer', (done) => {
10+
let image = sharp(fixtures.inputJpg);
11+
image.toBuffer({ resolveWithObject: true }).then((obj) => {
12+
image.toBuffer().then((buff) => {
13+
assert.strict.equal(Buffer.isBuffer(buff), true);
14+
assert.strict.equal(typeof obj, 'object');
15+
done();
16+
});
17+
});
18+
});
19+
});

0 commit comments

Comments
 (0)