Deprecate limitInputPixels and sequentialRead, move to input options

This commit is contained in:
Lovell Fuller
2020-01-12 19:59:39 +00:00
parent 6fdc79d569
commit bd52e93fca
14 changed files with 176 additions and 96 deletions

View File

@@ -460,8 +460,7 @@ async.series({
}).add('sharp-sequentialRead', {
defer: true,
fn: function (deferred) {
sharp(inputJpgBuffer)
.sequentialRead()
sharp(inputJpgBuffer, { sequentialRead: true })
.resize(width, height)
.toBuffer(function (err, buffer) {
if (err) {

View File

@@ -214,7 +214,27 @@ describe('Input/output', function () {
});
});
it('Sequential read, force JPEG', function (done) {
it('Invalid sequential read option throws', () => {
assert.throws(() => {
sharp({ sequentialRead: 'fail' });
}, /Expected boolean for sequentialRead but received fail of type string/);
});
it('Sequential read, force JPEG', () =>
sharp(fixtures.inputJpg, { sequentialRead: true })
.resize(320, 240)
.toFormat(sharp.format.jpeg)
.toBuffer({ resolveWithObject: true })
.then(({ data, info }) => {
assert.strictEqual(data.length > 0, true);
assert.strictEqual(data.length, info.size);
assert.strictEqual(info.format, 'jpeg');
assert.strictEqual(info.width, 320);
assert.strictEqual(info.height, 240);
})
);
it('Sequential read, force JPEG - deprecated', function (done) {
sharp(fixtures.inputJpg)
.sequentialRead()
.resize(320, 240)
@@ -230,7 +250,21 @@ describe('Input/output', function () {
});
});
it('Not sequential read, force JPEG', function (done) {
it('Not sequential read, force JPEG', () =>
sharp(fixtures.inputJpg, { sequentialRead: false })
.resize(320, 240)
.toFormat('jpeg')
.toBuffer({ resolveWithObject: true })
.then(({ data, info }) => {
assert.strictEqual(data.length > 0, true);
assert.strictEqual(data.length, info.size);
assert.strictEqual(info.format, 'jpeg');
assert.strictEqual(info.width, 320);
assert.strictEqual(info.height, 240);
})
);
it('Not sequential read, force JPEG - deprecated', function (done) {
sharp(fixtures.inputJpg)
.sequentialRead(false)
.resize(320, 240)
@@ -559,7 +593,67 @@ describe('Input/output', function () {
});
});
describe('Limit pixel count of input image', function () {
describe('Limit pixel count of input image', () => {
it('Invalid fails - negative', () => {
assert.throws(() => {
sharp({ limitInputPixels: -1 });
});
});
it('Invalid fails - float', () => {
assert.throws(() => {
sharp({ limitInputPixels: 12.3 });
});
});
it('Invalid fails - string', () => {
assert.throws(() => {
sharp({ limitInputPixels: 'fail' });
});
});
it('Same size as input works', () =>
sharp(fixtures.inputJpg)
.metadata()
.then(({ width, height }) =>
sharp(fixtures.inputJpg, { limitInputPixels: width * height }).toBuffer()
)
);
it('Disabling limit works', () =>
sharp(fixtures.inputJpgLarge, { limitInputPixels: false })
.resize(2)
.toBuffer()
);
it('Enabling default limit works and fails with a large image', () =>
sharp(fixtures.inputJpgLarge, { limitInputPixels: true })
.toBuffer()
.then(() => {
assert.fail('Expected to fail');
})
.catch(err => {
assert.strictEqual(err.message, 'Input image exceeds pixel limit');
})
);
it('Smaller than input fails', () =>
sharp(fixtures.inputJpg)
.metadata()
.then(({ width, height }) =>
sharp(fixtures.inputJpg, { limitInputPixels: width * height - 1 })
.toBuffer()
.then(() => {
assert.fail('Expected to fail');
})
.catch(err => {
assert.strictEqual(err.message, 'Input image exceeds pixel limit');
})
)
);
});
describe('Limit pixel count of input image - deprecated', function () {
it('Invalid fails - negative', function (done) {
let isValid = false;
try {