Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/deflate_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 3 additions & 2 deletions libdeflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion programs/gzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading