From 97d8e65dc839362cb55c65b3ae71caf15e55c4bb Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Thu, 26 Oct 2023 11:51:43 -0700 Subject: [PATCH] Match default compression level value in compress streams #726 --- mz_strm_bzip.c | 2 +- mz_strm_lzma.c | 2 +- mz_strm_zlib.c | 5 ++++- mz_strm_zstd.c | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mz_strm_bzip.c b/mz_strm_bzip.c index 331f3cda..c169998e 100644 --- a/mz_strm_bzip.c +++ b/mz_strm_bzip.c @@ -326,7 +326,7 @@ int32_t mz_stream_bzip_set_prop_int64(void *stream, int32_t prop, int64_t value) mz_stream_bzip *bzip = (mz_stream_bzip *)stream; switch (prop) { case MZ_STREAM_PROP_COMPRESS_LEVEL: - if (value < 0) + if (value == MZ_COMPRESS_LEVEL_DEFAULT) bzip->level = 6; else bzip->level = (int16_t)value; diff --git a/mz_strm_lzma.c b/mz_strm_lzma.c index 951546e9..5bedb720 100644 --- a/mz_strm_lzma.c +++ b/mz_strm_lzma.c @@ -415,7 +415,7 @@ int32_t mz_stream_lzma_set_prop_int64(void *stream, int32_t prop, int64_t value) mz_stream_lzma *lzma = (mz_stream_lzma *)stream; switch (prop) { case MZ_STREAM_PROP_COMPRESS_LEVEL: - if (value < 0 || value > 9) + if (value == MZ_COMPRESS_LEVEL_DEFAULT) lzma->preset = LZMA_PRESET_DEFAULT; else lzma->preset = (uint32_t)value; diff --git a/mz_strm_zlib.c b/mz_strm_zlib.c index 0cfc0611..cba63fb2 100644 --- a/mz_strm_zlib.c +++ b/mz_strm_zlib.c @@ -347,7 +347,10 @@ int32_t mz_stream_zlib_set_prop_int64(void *stream, int32_t prop, int64_t value) mz_stream_zlib *zlib = (mz_stream_zlib *)stream; switch (prop) { case MZ_STREAM_PROP_COMPRESS_LEVEL: - zlib->level = (int16_t)value; + if (value == MZ_COMPRESS_LEVEL_DEFAULT) + zlib->level = Z_DEFAULT_COMPRESSION; + else + zlib->level = (int16_t)value; break; case MZ_STREAM_PROP_TOTAL_IN_MAX: zlib->max_total_in = value; diff --git a/mz_strm_zstd.c b/mz_strm_zstd.c index 5d49bbe7..d009d5a3 100644 --- a/mz_strm_zstd.c +++ b/mz_strm_zstd.c @@ -312,7 +312,7 @@ int32_t mz_stream_zstd_set_prop_int64(void *stream, int32_t prop, int64_t value) mz_stream_zstd *zstd = (mz_stream_zstd *)stream; switch (prop) { case MZ_STREAM_PROP_COMPRESS_LEVEL: - if (value < 0) + if (value == MZ_COMPRESS_LEVEL_DEFAULT) zstd->preset = ZSTD_CLEVEL_DEFAULT; else zstd->preset = (int16_t)value;