mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Emit 'warning' event for non-critical problems #2032
This commit is contained in:
parent
8f5495a446
commit
19980190f7
@ -24,6 +24,9 @@ Requires libvips v8.9.1
|
|||||||
* Add experimental `sharpness` calculation to `stats()` response.
|
* Add experimental `sharpness` calculation to `stats()` response.
|
||||||
[#2251](https://github.com/lovell/sharp/issues/2251)
|
[#2251](https://github.com/lovell/sharp/issues/2251)
|
||||||
|
|
||||||
|
* Emit `warning` event for non-critical processing problems.
|
||||||
|
[#2032](https://github.com/lovell/sharp/issues/2032)
|
||||||
|
|
||||||
### v0.25.3 - 17th May 2020
|
### v0.25.3 - 17th May 2020
|
||||||
|
|
||||||
* Ensure libvips is initialised only once, improves worker thread safety.
|
* Ensure libvips is initialised only once, improves worker thread safety.
|
||||||
|
@ -45,8 +45,13 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* JPEG, PNG, WebP or TIFF format image data can be streamed out from this object.
|
* JPEG, PNG, WebP or TIFF format image data can be streamed out from this object.
|
||||||
* When using Stream based output, derived attributes are available from the `info` event.
|
* When using Stream based output, derived attributes are available from the `info` event.
|
||||||
*
|
*
|
||||||
|
* Non-critical problems encountered during processing are emitted as `warning` events.
|
||||||
|
*
|
||||||
* Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
* Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
||||||
*
|
*
|
||||||
|
* @emits Sharp#info
|
||||||
|
* @emits Sharp#warning
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* sharp('input.jpg')
|
* sharp('input.jpg')
|
||||||
* .resize(300, 200)
|
* .resize(300, 200)
|
||||||
@ -230,7 +235,10 @@ const Sharp = function (input, options) {
|
|||||||
linearA: 1,
|
linearA: 1,
|
||||||
linearB: 0,
|
linearB: 0,
|
||||||
// Function to notify of libvips warnings
|
// Function to notify of libvips warnings
|
||||||
debuglog: debuglog,
|
debuglog: warning => {
|
||||||
|
this.emit('warning', warning);
|
||||||
|
debuglog(warning);
|
||||||
|
},
|
||||||
// Function to notify of queue length changes
|
// Function to notify of queue length changes
|
||||||
queueListener: function (queueLength) {
|
queueListener: function (queueLength) {
|
||||||
Sharp.queue.emit('change', queueLength);
|
Sharp.queue.emit('change', queueLength);
|
||||||
|
@ -19,11 +19,17 @@ describe('failOnError', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles truncated PNG', function (done) {
|
it('handles truncated PNG, emits warnings', function (done) {
|
||||||
|
let isWarningEmitted = false;
|
||||||
sharp(fixtures.inputPngTruncated, { failOnError: false })
|
sharp(fixtures.inputPngTruncated, { failOnError: false })
|
||||||
|
.on('warning', function (warning) {
|
||||||
|
assert.strictEqual('not enough data', warning);
|
||||||
|
isWarningEmitted = true;
|
||||||
|
})
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, isWarningEmitted);
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user