Class: Zip::CentralDirectory

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Dirtyable
Defined in:
lib/zip/central_directory.rb

Overview

:nodoc:

Constant Summary collapse

END_OF_CD_SIG =
0x06054b50
ZIP64_END_OF_CD_SIG =
0x06064b50
ZIP64_EOCD_LOCATOR_SIG =
0x07064b50
STATIC_EOCD_SIZE =
22
ZIP64_STATIC_EOCD_SIZE =
56
ZIP64_EOCD_LOC_SIZE =
20
MAX_FILE_COMMENT_SIZE =
(1 << 16) - 1
MAX_END_OF_CD_SIZE =
MAX_FILE_COMMENT_SIZE + STATIC_EOCD_SIZE + ZIP64_EOCD_LOC_SIZE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Dirtyable

#dirty?, included

Constructor Details

#initialize(entries = EntrySet.new, comment = '') ⇒ CentralDirectory

:nodoc:



31
32
33
34
35
# File 'lib/zip/central_directory.rb', line 31

def initialize(entries = EntrySet.new, comment = '') #:nodoc:
  super(dirty_on_create: false)
  @entry_set = entries.kind_of?(EntrySet) ? entries : EntrySet.new(entries)
  @comment   = comment
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



23
24
25
# File 'lib/zip/central_directory.rb', line 23

def comment
  @comment
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



64
65
66
67
68
# File 'lib/zip/central_directory.rb', line 64

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

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

#count_entries(io) ⇒ Object

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.



59
60
61
62
# File 'lib/zip/central_directory.rb', line 59

def count_entries(io)
  read_eocds(io)
  @size
end

#read_from_stream(io) ⇒ Object



37
38
39
40
# File 'lib/zip/central_directory.rb', line 37

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

#write_to_stream(io) ⇒ Object

:nodoc:



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/zip/central_directory.rb', line 42

def write_to_stream(io) #:nodoc:
  cdir_offset = io.tell
  @entry_set.each { |entry| entry.write_c_dir_entry(io) }
  eocd_offset = io.tell
  cdir_size = eocd_offset - cdir_offset
  if Zip.write_zip64_support &&
     (cdir_offset > 0xFFFFFFFF || cdir_size > 0xFFFFFFFF || @entry_set.size > 0xFFFF)
    write_64_e_o_c_d(io, cdir_offset, cdir_size)
    write_64_eocd_locator(io, eocd_offset)
  end
  write_e_o_c_d(io, cdir_offset, cdir_size)
end