diff --git a/lib/deflate_compress.c b/lib/deflate_compress.c index 4a1f3276..b24087c2 100644 --- a/lib/deflate_compress.c +++ b/lib/deflate_compress.c @@ -3885,6 +3885,13 @@ libdeflate_alloc_compressor_ex(int compression_level, if (options->sizeof_options != sizeof(*options)) return NULL; + /* + * Note: For similarity with zlib's API, -1 is accepted as an alias for + * the default compression level. + */ + if (compression_level == -1) + compression_level = 6; + if (compression_level < 0 || compression_level > 12) return NULL; diff --git a/libdeflate.h b/libdeflate.h index d6c885f2..fa01ea8c 100644 --- a/libdeflate.h +++ b/libdeflate.h @@ -43,10 +43,11 @@ struct libdeflate_options; * level on a zlib-like scale but with a higher maximum value (1 = fastest, 6 = * medium/default, 9 = slow, 12 = slowest). Level 0 is also supported and means * "no compression", specifically "create a valid stream, but only emit - * uncompressed blocks" (this will expand the data slightly). + * uncompressed blocks" (this will expand the data slightly). Level -1 is an + * alias indicating a default level of 6. * * The return value is a pointer to the new compressor, or NULL if out of memory - * or if the compression level is invalid (i.e. outside the range [0, 12]). + * or if the compression level is invalid (i.e. outside the range [-1, 12]). * * Note: for compression, the sliding window size is defined at compilation time * to 32768, the largest size permissible in the DEFLATE format. It cannot be diff --git a/programs/gzip.c b/programs/gzip.c index 2c753778..597c702b 100644 --- a/programs/gzip.c +++ b/programs/gzip.c @@ -563,7 +563,7 @@ tmain(int argc, tchar *argv[]) options.force = false; options.keep = false; options.test = false; - options.compression_level = 6; + options.compression_level = -1; options.suffix = T(".gz"); while ((opt_char = tgetopt(argc, argv, optstring)) != -1) {