Skip to content

Commit

Permalink
Revert to ::Zip::File unless password
Browse files Browse the repository at this point in the history
  • Loading branch information
JoriPeterson committed Nov 11, 2024
1 parent aa23e02 commit 5586a31
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/rhykane/s3/get.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ def filename_parts
[filename.to_s.split(extname), extname].flatten
end

def stream_zip(zip, wr_io) = new_zip_stream(zip) do |zip_file| stream_entries(zip_file, wr_io) end
def stream_zip(zip, wr_io)
if decrypter
new_zip_stream(zip) do |zip_file| stream_pw_entries(zip_file, wr_io) end
else
::Zip::File.open_buffer(zip) do |zip_file| stream_entries(zip_file, wr_io) end
end
end

def new_zip_stream(zip, &) = ::Zip::InputStream.open(zip, 0, decrypter, &)
def decrypter = (pwd = opts[:password]) && Zip::TraditionalDecrypter.new(pwd)

ENTRY_EXCLUDE_PATTERN = /(__MACOSX|\.DS_Store)/
ARCHIVE_GLOB_PATTERN = '{[!__MAC*]*,[!*DS_Store*],*}'

def stream_entries(input_io, wr_io)
def stream_pw_entries(input_io, wr_io)
return_header = true
while (entry = input_io.get_next_entry)
next if entry.name.match?(self.class::ENTRY_EXCLUDE_PATTERN)
Expand All @@ -88,6 +96,16 @@ def stream_entries(input_io, wr_io)
IO.copy_stream(input_io, wr_io)
end
end

def stream_entries(entries, wr_io)
return_header = true
entries.glob(ARCHIVE_GLOB_PATTERN).map(&:get_input_stream).each do |io|
header = io.readline
wr_io << header if return_header
return_header = false
IO.copy_stream(io, wr_io)
end
end
end

class Ungzip < Unzip
Expand Down

0 comments on commit 5586a31

Please sign in to comment.