Skip to content

Commit

Permalink
Reorder methods in CentralDirectory with private at the end.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Jan 17, 2022
1 parent bdbd573 commit 60f8fff
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions lib/zip/central_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def initialize(entries = EntrySet.new, comment = '') #:nodoc:
@comment = comment
end

def read_from_stream(io)
read_eocds(io)
read_central_directory_entries(io)
end

def write_to_stream(io) #:nodoc:
cdir_offset = io.tell
@entry_set.each { |entry| entry.write_c_dir_entry(io) }
Expand All @@ -46,6 +51,23 @@ def write_to_stream(io) #:nodoc:
write_e_o_c_d(io, cdir_offset, cdir_size)
end

# Reads the End of Central Directory Record (and the Zip64 equivalent if
# needs be) and returns the number of entries in the archive. This is a
# convenience method that avoids reading in all of the entry data to get a
# very quick entry count.
def count_entries(io)
read_eocds(io)
@size
end

def ==(other) #:nodoc:
return false unless other.kind_of?(CentralDirectory)

@entry_set.entries.sort == other.entries.sort && comment == other.comment
end

private

def write_e_o_c_d(io, offset, cdir_size) #:nodoc:
tmp = [
END_OF_CD_SIG,
Expand All @@ -61,8 +83,6 @@ def write_e_o_c_d(io, offset, cdir_size) #:nodoc:
io << @comment
end

private :write_e_o_c_d

def write_64_e_o_c_d(io, offset, cdir_size) #:nodoc:
tmp = [
ZIP64_END_OF_CD_SIG,
Expand All @@ -79,8 +99,6 @@ def write_64_e_o_c_d(io, offset, cdir_size) #:nodoc:
io << tmp.pack('VQ<vvVVQ<Q<Q<Q<')
end

private :write_64_e_o_c_d

def write_64_eocd_locator(io, zip64_eocd_offset)
tmp = [
ZIP64_EOCD_LOCATOR_SIG,
Expand All @@ -91,8 +109,6 @@ def write_64_eocd_locator(io, zip64_eocd_offset)
io << tmp.pack('VVQ<V')
end

private :write_64_eocd_locator

def unpack_64_e_o_c_d(buffer) #:nodoc:
_, # ZIP64_END_OF_CD_SIG. We know we have this at this point.
@size_of_zip64_e_o_c_d,
Expand Down Expand Up @@ -192,11 +208,6 @@ def read_local_extra_field(io)
io.read(e_len)
end

def read_from_stream(io) #:nodoc:
read_eocds(io)
read_central_directory_entries(io)
end

def read_eocds(io) #:nodoc:
base_location, data = eocd_data(io)

Expand Down Expand Up @@ -238,21 +249,6 @@ def eocd_data(io)

[io.tell, io.read]
end

# Reads the End of Central Directory Record (and the Zip64 equivalent if
# needs be) and returns the number of entries in the archive. This is a
# convenience method that avoids reading in all of the entry data to get a
# very quick entry count.
def count_entries(io)
read_eocds(io)
@size
end

def ==(other) #:nodoc:
return false unless other.kind_of?(CentralDirectory)

@entry_set.entries.sort == other.entries.sort && comment == other.comment
end
end
end

Expand Down

0 comments on commit 60f8fff

Please sign in to comment.