From e63bb689fa074125acb698efbbaf49eca4a71600 Mon Sep 17 00:00:00 2001 From: f3fora <33097027+f3fora@users.noreply.github.com> Date: Fri, 25 Mar 2022 08:38:23 +0100 Subject: [PATCH 1/6] fix: correct edge values of window_bits see https://docs.python.org/3/library/zlib.html --- src/compression.jl | 16 ++++++++-------- src/decompression.jl | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/compression.jl b/src/compression.jl index 19bec23..cc114d1 100644 --- a/src/compression.jl +++ b/src/compression.jl @@ -25,14 +25,14 @@ Create a gzip compression codec. Arguments --------- - `level`: compression level (-1..9) -- `windowbits`: size of history buffer (8..15) +- `windowbits`: size of history buffer (9..15) """ function GzipCompressor(;level::Integer=Z_DEFAULT_COMPRESSION, windowbits::Integer=Z_DEFAULT_WINDOWBITS) if !(-1 ≤ level ≤ 9) throw(ArgumentError("compression level must be within -1..9")) - elseif !(8 ≤ windowbits ≤ 15) - throw(ArgumentError("windowbits must be within 8..15")) + elseif !(9 ≤ windowbits ≤ 15) + throw(ArgumentError("windowbits must be within 9..15")) end return GzipCompressor(ZStream(), level, windowbits+16) end @@ -67,14 +67,14 @@ Create a zlib compression codec. Arguments --------- - `level`: compression level (-1..9) -- `windowbits`: size of history buffer (8..15) +- `windowbits`: size of history buffer (9..15) or (-15..-9) """ function ZlibCompressor(;level::Integer=Z_DEFAULT_COMPRESSION, windowbits::Integer=Z_DEFAULT_WINDOWBITS) if !(-1 ≤ level ≤ 9) throw(ArgumentError("compression level must be within -1..9")) - elseif !(8 ≤ windowbits ≤ 15) - throw(ArgumentError("windowbits must be within 8..15")) + elseif !(9 ≤ abs(windowbits) ≤ 15) + throw(ArgumentError("|windowbits| must be within 9..15")) end return ZlibCompressor(ZStream(), level, windowbits) end @@ -115,8 +115,8 @@ function DeflateCompressor(;level::Integer=Z_DEFAULT_COMPRESSION, windowbits::Integer=Z_DEFAULT_WINDOWBITS) if !(-1 ≤ level ≤ 9) throw(ArgumentError("compression level must be within -1..9")) - elseif !(8 ≤ windowbits ≤ 15) - throw(ArgumentError("windowbits must be within 8..15")) + elseif !(9 ≤ windowbits ≤ 15) + throw(ArgumentError("windowbits must be within 9..15")) end return DeflateCompressor(ZStream(), level, -Int(windowbits)) end diff --git a/src/decompression.jl b/src/decompression.jl index 8b647cf..3a3146a 100644 --- a/src/decompression.jl +++ b/src/decompression.jl @@ -63,11 +63,11 @@ Create a zlib decompression codec. Arguments --------- -- `windowbits`: size of history buffer (8..15) +- `windowbits`: size of history buffer (8..15) or (-15..-8) or 0 """ function ZlibDecompressor(;windowbits::Integer=Z_DEFAULT_WINDOWBITS) - if !(8 ≤ windowbits ≤ 15) - throw(ArgumentError("windowbits must be within 8..15")) + if !(8 ≤ abs(windowbits) ≤ 15) || windowbits == 0 + throw(ArgumentError("|windowbits| must be within 8..15 or 0")) end return ZlibDecompressor(ZStream(), windowbits) end From d88a264992beb104a684ae497eb710cc2ec8816e Mon Sep 17 00:00:00 2001 From: Nathan Zimmerberg <39104088+nhz2@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:27:20 -0500 Subject: [PATCH 2/6] Update src/compression.jl --- src/compression.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compression.jl b/src/compression.jl index cc114d1..ebc5ef9 100644 --- a/src/compression.jl +++ b/src/compression.jl @@ -67,7 +67,7 @@ Create a zlib compression codec. Arguments --------- - `level`: compression level (-1..9) -- `windowbits`: size of history buffer (9..15) or (-15..-9) +- `windowbits`: size of history buffer (9..15) """ function ZlibCompressor(;level::Integer=Z_DEFAULT_COMPRESSION, windowbits::Integer=Z_DEFAULT_WINDOWBITS) From 305d59c9c9ce0a923d93905acb42f721702a7c37 Mon Sep 17 00:00:00 2001 From: Nathan Zimmerberg <39104088+nhz2@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:27:26 -0500 Subject: [PATCH 3/6] Update src/compression.jl --- src/compression.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compression.jl b/src/compression.jl index ebc5ef9..0457a8e 100644 --- a/src/compression.jl +++ b/src/compression.jl @@ -73,8 +73,8 @@ function ZlibCompressor(;level::Integer=Z_DEFAULT_COMPRESSION, windowbits::Integer=Z_DEFAULT_WINDOWBITS) if !(-1 ≤ level ≤ 9) throw(ArgumentError("compression level must be within -1..9")) - elseif !(9 ≤ abs(windowbits) ≤ 15) - throw(ArgumentError("|windowbits| must be within 9..15")) + elseif !(9 ≤ windowbits ≤ 15) + throw(ArgumentError("windowbits must be within 9..15")) end return ZlibCompressor(ZStream(), level, windowbits) end From f179a6320620c13a1ff6648cf4513dee4b98212b Mon Sep 17 00:00:00 2001 From: Nathan Zimmerberg <39104088+nhz2@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:27:34 -0500 Subject: [PATCH 4/6] Update src/decompression.jl --- src/decompression.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/decompression.jl b/src/decompression.jl index 3a3146a..89b5ad8 100644 --- a/src/decompression.jl +++ b/src/decompression.jl @@ -63,7 +63,7 @@ Create a zlib decompression codec. Arguments --------- -- `windowbits`: size of history buffer (8..15) or (-15..-8) or 0 +- `windowbits`: size of history buffer (8..15) """ function ZlibDecompressor(;windowbits::Integer=Z_DEFAULT_WINDOWBITS) if !(8 ≤ abs(windowbits) ≤ 15) || windowbits == 0 From 91c97bbef91cb37385d7bd8dd9dc8fecbf088f7d Mon Sep 17 00:00:00 2001 From: Nathan Zimmerberg <39104088+nhz2@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:27:44 -0500 Subject: [PATCH 5/6] Update src/decompression.jl --- src/decompression.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/decompression.jl b/src/decompression.jl index 89b5ad8..8b647cf 100644 --- a/src/decompression.jl +++ b/src/decompression.jl @@ -66,8 +66,8 @@ Arguments - `windowbits`: size of history buffer (8..15) """ function ZlibDecompressor(;windowbits::Integer=Z_DEFAULT_WINDOWBITS) - if !(8 ≤ abs(windowbits) ≤ 15) || windowbits == 0 - throw(ArgumentError("|windowbits| must be within 8..15 or 0")) + if !(8 ≤ windowbits ≤ 15) + throw(ArgumentError("windowbits must be within 8..15")) end return ZlibDecompressor(ZStream(), windowbits) end From e6fdac9e056184c108f228fa4c3a507deaeeb565 Mon Sep 17 00:00:00 2001 From: Nathan Zimmerberg <39104088+nhz2@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:29:08 -0500 Subject: [PATCH 6/6] Make docstring match error. --- src/compression.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compression.jl b/src/compression.jl index a468d44..82955fc 100644 --- a/src/compression.jl +++ b/src/compression.jl @@ -109,7 +109,7 @@ Create a deflate compression codec. Arguments --------- - `level`: compression level (-1..9) -- `windowbits`: size of history buffer (8..15) +- `windowbits`: size of history buffer (9..15) """ function DeflateCompressor(;level::Integer=Z_DEFAULT_COMPRESSION, windowbits::Integer=Z_DEFAULT_WINDOWBITS)