From 737a327cba97a8c08922fc140d42b7531b7f972d Mon Sep 17 00:00:00 2001 From: "Clark C. Evans" Date: Tue, 17 Oct 2023 22:34:44 -0400 Subject: [PATCH 1/2] permitting deflate level to be set --- src/ZipFile.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ZipFile.jl b/src/ZipFile.jl index eb1b5df..dc9ad6d 100644 --- a/src/ZipFile.jl +++ b/src/ZipFile.jl @@ -605,7 +605,7 @@ uncompressed or Deflate for compressed). Mtime is the modification time of the file. """ -function addfile(w::Writer, name::AbstractString; method::Integer=Store, mtime::Float64=-1.0) +function addfile(w::Writer, name::AbstractString; method::Integer=Store, mtime::Float64=-1.0, deflate_level::Integer=6) if w._current !== nothing close(w._current) w._current = nothing @@ -636,7 +636,7 @@ function addfile(w::Writer, name::AbstractString; method::Integer=Store, mtime:: f._datapos = position(w._io) if f.method == Deflate - f._zio = Zlib.Writer(f._io, true) + f._zio = Zlib.Writer(f._io, deflate_level, true) end w.files = [w.files; f] w._current = f From 8a52e80de06f5ef49eba71ed65868d88c316158f Mon Sep 17 00:00:00 2001 From: "Clark C. Evans" Date: Tue, 17 Oct 2023 23:38:01 -0400 Subject: [PATCH 2/2] perhaps setting of deflate_level should imply deflate --- src/ZipFile.jl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/ZipFile.jl b/src/ZipFile.jl index dc9ad6d..f60db53 100644 --- a/src/ZipFile.jl +++ b/src/ZipFile.jl @@ -596,16 +596,20 @@ end """ addfile(w::Writer, name::AbstractString; method::Integer=Store, mtime::Float64=-1.0) -Add a new file named name into the ZIP file writer w, and return the +Add a new file named `name` into the ZIP file writer `w`, and return the WritableFile for the new file. We don't allow concurrrent writes, thus the file previously added using this function will be closed. -Method specifies the compression method that will be used (Store for +Method specifies the compression `method` that will be used (Store for uncompressed or Deflate for compressed). -Mtime is the modification time of the file. +Method provides a `deflate_level` option which if provided implies a +`Deflate` compression method. When `Deflate` is specified as the `method`, +the default `deflate_level` is 6. + +`Mtime` is the modification time of the file. """ -function addfile(w::Writer, name::AbstractString; method::Integer=Store, mtime::Float64=-1.0, deflate_level::Integer=6) +function addfile(w::Writer, name::AbstractString; method::Integer=Store, mtime::Float64=-1.0, deflate_level=nothing) if w._current !== nothing close(w._current) w._current = nothing @@ -635,8 +639,8 @@ function addfile(w::Writer, name::AbstractString; method::Integer=Store, mtime:: _writele(w._io, b) f._datapos = position(w._io) - if f.method == Deflate - f._zio = Zlib.Writer(f._io, deflate_level, true) + if f.method == Deflate || !isnothing(deflate_level) + f._zio = Zlib.Writer(f._io, something(deflate_level, 6), true) end w.files = [w.files; f] w._current = f