Class: Omnizip::Formats::Zip::Zip64EndOfCentralDirectory

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/omnizip/formats/zip/zip64_end_of_central_directory.rb

Overview

ZIP64 End of Central Directory Record Used when the archive exceeds ZIP format limits (>4GB or >65535 entries)

Constant Summary

Constants included from Constants

Constants::ATTR_ARCHIVE, Constants::ATTR_DIRECTORY, Constants::CENTRAL_DIRECTORY_SIGNATURE, Constants::COMPRESSION_BZIP2, Constants::COMPRESSION_DEFLATE, Constants::COMPRESSION_DEFLATE64, Constants::COMPRESSION_IMPLODED, Constants::COMPRESSION_LZMA, Constants::COMPRESSION_PPMD, Constants::COMPRESSION_REDUCED_1, Constants::COMPRESSION_REDUCED_2, Constants::COMPRESSION_REDUCED_3, Constants::COMPRESSION_REDUCED_4, Constants::COMPRESSION_SHRUNK, Constants::COMPRESSION_STORE, Constants::COMPRESSION_ZSTANDARD, Constants::DATA_DESCRIPTOR_SIGNATURE, Constants::END_OF_CENTRAL_DIRECTORY_SIGNATURE, Constants::FLAG_DATA_DESCRIPTOR, Constants::FLAG_ENCRYPTED, Constants::FLAG_STRONG_ENCRYPTION, Constants::FLAG_UTF8, Constants::LOCAL_FILE_HEADER_SIGNATURE, Constants::MAX_COMMENT_LENGTH, Constants::UNIX_DIR_PERMISSIONS, Constants::UNIX_EXTRA_FIELD_TAG, Constants::UNIX_FILE_PERMISSIONS, Constants::UNIX_SYMLINK_PERMISSIONS, Constants::VERSION_BZIP2, Constants::VERSION_DEFAULT, Constants::VERSION_DEFLATE, Constants::VERSION_LZMA, Constants::VERSION_MADE_BY_UNIX, Constants::VERSION_MADE_BY_WINDOWS, Constants::VERSION_ZIP64, Constants::ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIGNATURE, Constants::ZIP64_END_OF_CENTRAL_DIRECTORY_SIGNATURE, Constants::ZIP64_EXTRA_FIELD_TAG, Constants::ZIP64_LIMIT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature: ZIP64_END_OF_CENTRAL_DIRECTORY_SIGNATURE, record_size: 44, version_made_by: VERSION_MADE_BY_UNIX | VERSION_ZIP64, version_needed: VERSION_ZIP64, disk_number: 0, disk_number_with_cd: 0, total_entries_this_disk: 0, total_entries: 0, central_directory_size: 0, central_directory_offset: 0, extensible_data_sector: "") ⇒ Zip64EndOfCentralDirectory

Returns a new instance of Zip64EndOfCentralDirectory.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 17

def initialize(
  signature: ZIP64_END_OF_CENTRAL_DIRECTORY_SIGNATURE,
  record_size: 44, # Size of remaining record (not including signature and size field)
  version_made_by: VERSION_MADE_BY_UNIX | VERSION_ZIP64,
  version_needed: VERSION_ZIP64,
  disk_number: 0,
  disk_number_with_cd: 0,
  total_entries_this_disk: 0,
  total_entries: 0,
  central_directory_size: 0,
  central_directory_offset: 0,
  extensible_data_sector: ""
)
  @signature = signature
  @record_size = record_size
  @version_made_by = version_made_by
  @version_needed = version_needed
  @disk_number = disk_number
  @disk_number_with_cd = disk_number_with_cd
  @total_entries_this_disk = total_entries_this_disk
  @total_entries = total_entries
  @central_directory_size = central_directory_size
  @central_directory_offset = central_directory_offset
  @extensible_data_sector = extensible_data_sector
end

Instance Attribute Details

#central_directory_offsetObject

Returns the value of attribute central_directory_offset.



11
12
13
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 11

def central_directory_offset
  @central_directory_offset
end

#central_directory_sizeObject

Returns the value of attribute central_directory_size.



11
12
13
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 11

def central_directory_size
  @central_directory_size
end

#disk_numberObject

Returns the value of attribute disk_number.



11
12
13
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 11

def disk_number
  @disk_number
end

#disk_number_with_cdObject

Returns the value of attribute disk_number_with_cd.



11
12
13
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 11

def disk_number_with_cd
  @disk_number_with_cd
end

#extensible_data_sectorObject

Returns the value of attribute extensible_data_sector.



11
12
13
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 11

def extensible_data_sector
  @extensible_data_sector
end

#record_sizeObject

Returns the value of attribute record_size.



11
12
13
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 11

def record_size
  @record_size
end

#signatureObject

Returns the value of attribute signature.



11
12
13
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 11

def signature
  @signature
end

#total_entriesObject

Returns the value of attribute total_entries.



11
12
13
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 11

def total_entries
  @total_entries
end

#total_entries_this_diskObject

Returns the value of attribute total_entries_this_disk.



11
12
13
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 11

def total_entries_this_disk
  @total_entries_this_disk
end

#version_made_byObject

Returns the value of attribute version_made_by.



11
12
13
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 11

def version_made_by
  @version_made_by
end

#version_neededObject

Returns the value of attribute version_needed.



11
12
13
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 11

def version_needed
  @version_needed
end

Class Method Details

.from_binary(data) ⇒ Object

Parse from binary data



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 62

def self.from_binary(data)
  signature, record_size, version_made_by, version_needed,
  disk_number, disk_number_with_cd,
  total_entries_this_disk, total_entries,
  central_directory_size, central_directory_offset = data.unpack("VQvvVVQQQQ")

  unless signature == ZIP64_END_OF_CENTRAL_DIRECTORY_SIGNATURE
    raise Omnizip::FormatError,
          "Invalid ZIP64 EOCD signature"
  end

  # Extensible data sector starts after the fixed 56 bytes (4+8+2+2+4+4+8+8+8+8)
  extensible_data_sector = if data.bytesize > 56
                             data[56..]
                           else
                             ""
                           end

  new(
    signature: signature,
    record_size: record_size,
    version_made_by: version_made_by,
    version_needed: version_needed,
    disk_number: disk_number,
    disk_number_with_cd: disk_number_with_cd,
    total_entries_this_disk: total_entries_this_disk,
    total_entries: total_entries,
    central_directory_size: central_directory_size,
    central_directory_offset: central_directory_offset,
    extensible_data_sector: extensible_data_sector,
  )
end

Instance Method Details

#to_binaryObject

Serialize to binary format



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 44

def to_binary
  @record_size = 44 + extensible_data_sector.bytesize

  [
    signature,
    record_size,
    version_made_by,
    version_needed,
    disk_number,
    disk_number_with_cd,
    total_entries_this_disk,
    total_entries,
    central_directory_size,
    central_directory_offset,
  ].pack("VQvvVVQQQQ") + extensible_data_sector.b
end

#total_sizeObject

Total size of this record in bytes



96
97
98
# File 'lib/omnizip/formats/zip/zip64_end_of_central_directory.rb', line 96

def total_size
  12 + record_size # 4 (signature) + 8 (record_size) + record_size
end