Emit 'warning' event for non-critical problems #2032

This commit is contained in:
Lovell Fuller
2020-06-12 13:46:12 +01:00
parent 8f5495a446
commit 19980190f7
3 changed files with 19 additions and 2 deletions

View File

@@ -45,8 +45,13 @@ const debuglog = util.debuglog('sharp');
* 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.
*
* 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.
*
* @emits Sharp#info
* @emits Sharp#warning
*
* @example
* sharp('input.jpg')
* .resize(300, 200)
@@ -230,7 +235,10 @@ const Sharp = function (input, options) {
linearA: 1,
linearB: 0,
// Function to notify of libvips warnings
debuglog: debuglog,
debuglog: warning => {
this.emit('warning', warning);
debuglog(warning);
},
// Function to notify of queue length changes
queueListener: function (queueLength) {
Sharp.queue.emit('change', queueLength);