From cd9a3fcad1a46bcaf29a30033a11ad6dff72211a Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Thu, 10 Jun 2021 17:29:00 +0100 Subject: [PATCH] Move all the `read_zip_*` methods out of `Entry`. They were only ever used in `CentralDirectory` anyway. --- lib/zip/central_directory.rb | 46 +++++++++++++++++++++++------------- lib/zip/entry.rb | 12 ---------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/lib/zip/central_directory.rb b/lib/zip/central_directory.rb index 36a150b..d6f5b0c 100644 --- a/lib/zip/central_directory.rb +++ b/lib/zip/central_directory.rb @@ -88,28 +88,28 @@ module Zip def read_64_e_o_c_d(buf) #:nodoc: buf = get_64_e_o_c_d(buf) - @size_of_zip64_e_o_c_d = Entry.read_zip_64_long(buf) - @version_made_by = Entry.read_zip_short(buf) - @version_needed_for_extract = Entry.read_zip_short(buf) - @number_of_this_disk = Entry.read_zip_long(buf) - @number_of_disk_with_start_of_cdir = Entry.read_zip_long(buf) - @total_number_of_entries_in_cdir_on_this_disk = Entry.read_zip_64_long(buf) - @size = Entry.read_zip_64_long(buf) - @size_in_bytes = Entry.read_zip_64_long(buf) - @cdir_offset = Entry.read_zip_64_long(buf) + @size_of_zip64_e_o_c_d = read_long64(buf) + @version_made_by = read_short(buf) + @version_needed_for_extract = read_short(buf) + @number_of_this_disk = read_long(buf) + @number_of_disk_with_start_of_cdir = read_long(buf) + @total_number_of_entries_in_cdir_on_this_disk = read_long64(buf) + @size = read_long64(buf) + @size_in_bytes = read_long64(buf) + @cdir_offset = read_long64(buf) @zip_64_extensible = buf.slice!(0, buf.bytesize) raise Error, 'Zip consistency problem while reading eocd structure' unless buf.empty? end def read_e_o_c_d(buf) #:nodoc: buf = get_e_o_c_d(buf) - @number_of_this_disk = Entry.read_zip_short(buf) - @number_of_disk_with_start_of_cdir = Entry.read_zip_short(buf) - @total_number_of_entries_in_cdir_on_this_disk = Entry.read_zip_short(buf) - @size = Entry.read_zip_short(buf) - @size_in_bytes = Entry.read_zip_long(buf) - @cdir_offset = Entry.read_zip_long(buf) - comment_length = Entry.read_zip_short(buf) + @number_of_this_disk = read_short(buf) + @number_of_disk_with_start_of_cdir = read_short(buf) + @total_number_of_entries_in_cdir_on_this_disk = read_short(buf) + @size = read_short(buf) + @size_in_bytes = read_long(buf) + @cdir_offset = read_long(buf) + comment_length = read_short(buf) @comment = if comment_length.to_i <= 0 buf.slice!(0, buf.size) else @@ -233,6 +233,20 @@ module Zip @entry_set.entries.sort == other.entries.sort && comment == other.comment end + + private + + def read_short(io) # :nodoc: + io.read(2).unpack1('v') + end + + def read_long(io) # :nodoc: + io.read(4).unpack1('V') + end + + def read_long64(io) # :nodoc: + io.read(8).unpack1('Q<') + end end end diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index 2327cd0..cdff9ba 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -230,18 +230,6 @@ module Zip end class << self - def read_zip_short(io) # :nodoc: - io.read(2).unpack1('v') - end - - def read_zip_long(io) # :nodoc: - io.read(4).unpack1('V') - end - - def read_zip_64_long(io) # :nodoc: - io.read(8).unpack1('Q<') - end - def read_c_dir_entry(io) #:nodoc:all path = if io.respond_to?(:path) io.path