diff --git a/README.md b/README.md index f0fa2b52..4e073dfe 100755 --- a/README.md +++ b/README.md @@ -378,7 +378,7 @@ Include all metadata (ICC, EXIF, XMP) from the input image in the output image. An advanced setting for the _zlib_ compression level of the lossless PNG output format. The default level is `6`. -`compressionLevel` is a Number between -1 and 9. +`compressionLevel` is a Number between 0 and 9. ### Output methods diff --git a/index.js b/index.js index 380199aa..ede6c40a 100755 --- a/index.js +++ b/index.js @@ -63,6 +63,7 @@ util.inherits(Sharp, stream.Duplex); Handle incoming chunk on Writable Stream */ Sharp.prototype._write = function(chunk, encoding, callback) { + /*jslint unused: false */ if (this.options.streamIn) { if (typeof chunk === 'object' || chunk instanceof Buffer) { if (typeof this.options.bufferIn === 'undefined') { @@ -229,10 +230,10 @@ Sharp.prototype.quality = function(quality) { }; Sharp.prototype.compressionLevel = function(compressionLevel) { - if (!Number.isNaN(compressionLevel) && compressionLevel >= -1 && compressionLevel <= 9) { + if (!Number.isNaN(compressionLevel) && compressionLevel >= 0 && compressionLevel <= 9) { this.options.compressionLevel = compressionLevel; } else { - throw new Error('Invalid compressionLevel (-1 to 9) ' + compressionLevel); + throw new Error('Invalid compressionLevel (0 to 9) ' + compressionLevel); } return this; }; diff --git a/tests/unit.js b/tests/unit.js index 305b4c85..caabe4de 100755 --- a/tests/unit.js +++ b/tests/unit.js @@ -815,6 +815,26 @@ async.series([ done(); }); }, + // PNG compression level - valid + function(done) { + var isValid = false; + try { + sharp().compressionLevel(0); + isValid = true; + } catch (e) {} + assert(isValid); + done(); + }, + // PNG compression level - invalid + function(done) { + var isValid = false; + try { + sharp().compressionLevel(-1); + isValid = true; + } catch (e) {} + assert(!isValid); + done(); + }, // Verify internal counters function(done) { var counters = sharp.counters();