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.
|
||||
[#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
|
||||
|
||||
* 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.
|
||||
* 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);
|
||||
|
@ -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 })
|
||||
.on('warning', function (warning) {
|
||||
assert.strictEqual('not enough data', warning);
|
||||
isWarningEmitted = true;
|
||||
})
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, isWarningEmitted);
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
|
Loading…
x
Reference in New Issue
Block a user