Class: Rant::Archive::Rubyzip::ZipCentralDirectory
- Includes:
- Enumerable
- Defined in:
- lib/rant/archive/rubyzip.rb
Direct Known Subclasses
Constant Summary collapse
- END_OF_CENTRAL_DIRECTORY_SIGNATURE =
0x06054b50
- MAX_END_OF_CENTRAL_DIRECTORY_STRUCTURE_SIZE =
65536 + 18
- STATIC_EOCD_SIZE =
22
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
Class Method Summary collapse
-
.read_from_stream(io) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#each(&proc) ⇒ Object
For iterating over the entries.
-
#entries ⇒ Object
Returns an Enumerable containing the entries.
-
#get_e_o_c_d(io) ⇒ Object
:nodoc:.
-
#initialize(entries = ZipEntrySet.new, comment = "") ⇒ ZipCentralDirectory
constructor
:nodoc:.
-
#read_central_directory_entries(io) ⇒ Object
:nodoc:.
-
#read_e_o_c_d(io) ⇒ Object
:nodoc:.
-
#read_from_stream(io) ⇒ Object
:nodoc:.
-
#size ⇒ Object
Returns the number of entries in the central directory (and consequently in the zip archive).
-
#write_to_stream(io) ⇒ Object
:nodoc:.
Methods included from Enumerable
Constructor Details
#initialize(entries = ZipEntrySet.new, comment = "") ⇒ ZipCentralDirectory
:nodoc:
861 862 863 864 865 |
# File 'lib/rant/archive/rubyzip.rb', line 861 def initialize(entries = ZipEntrySet.new, comment = "") #:nodoc: super() @entrySet = entries.kind_of?(ZipEntrySet) ? entries : ZipEntrySet.new(entries) @comment = comment end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
854 855 856 |
# File 'lib/rant/archive/rubyzip.rb', line 854 def comment @comment end |
Class Method Details
.read_from_stream(io) ⇒ Object
:nodoc:
952 953 954 955 956 957 958 |
# File 'lib/rant/archive/rubyzip.rb', line 952 def ZipCentralDirectory.read_from_stream(io) #:nodoc: cdir = new cdir.read_from_stream(io) return cdir rescue ZipError return nil end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
960 961 962 963 |
# File 'lib/rant/archive/rubyzip.rb', line 960 def == (other) #:nodoc: return false unless other.kind_of?(ZipCentralDirectory) @entrySet.entries.sort == other.entries.sort && comment == other.comment end |
#each(&proc) ⇒ Object
For iterating over the entries.
942 943 944 |
# File 'lib/rant/archive/rubyzip.rb', line 942 def each(&proc) @entrySet.each(&proc) end |
#entries ⇒ Object
Returns an Enumerable containing the entries.
857 858 859 |
# File 'lib/rant/archive/rubyzip.rb', line 857 def entries @entrySet.entries end |
#get_e_o_c_d(io) ⇒ Object
:nodoc:
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 |
# File 'lib/rant/archive/rubyzip.rb', line 923 def get_e_o_c_d(io) #:nodoc: begin io.seek(-MAX_END_OF_CENTRAL_DIRECTORY_STRUCTURE_SIZE, IO::SEEK_END) rescue Errno::EINVAL io.seek(0, IO::SEEK_SET) rescue Errno::EFBIG # FreeBSD 4.9 returns Errno::EFBIG instead of Errno::EINVAL io.seek(0, IO::SEEK_SET) end buf = io.read sigIndex = buf.rindex([END_OF_CENTRAL_DIRECTORY_SIGNATURE].pack('V')) raise ZipError, "Zip end of central directory signature not found" unless sigIndex buf=buf.slice!((sigIndex+4)...(buf.size)) def buf.read(count) slice!(0, count) end return buf end |
#read_central_directory_entries(io) ⇒ Object
:nodoc:
906 907 908 909 910 911 912 913 914 915 916 |
# File 'lib/rant/archive/rubyzip.rb', line 906 def read_central_directory_entries(io) #:nodoc: begin io.seek(@cdirOffset, IO::SEEK_SET) rescue Errno::EINVAL raise ZipError, "Zip consistency problem while reading central directory entry" end @entrySet = ZipEntrySet.new @size.times { @entrySet << ZipEntry.read_c_dir_entry(io) } end |
#read_e_o_c_d(io) ⇒ Object
:nodoc:
893 894 895 896 897 898 899 900 901 902 903 904 |
# File 'lib/rant/archive/rubyzip.rb', line 893 def read_e_o_c_d(io) #:nodoc: buf = get_e_o_c_d(io) @numberOfThisDisk = ZipEntry::read_zip_short(buf) @numberOfDiskWithStartOfCDir = ZipEntry::read_zip_short(buf) @totalNumberOfEntriesInCDirOnThisDisk = ZipEntry::read_zip_short(buf) @size = ZipEntry::read_zip_short(buf) @sizeInBytes = ZipEntry::read_zip_long(buf) @cdirOffset = ZipEntry::read_zip_long(buf) commentLength = ZipEntry::read_zip_short(buf) @comment = buf.read(commentLength) raise ZipError, "Zip consistency problem while reading eocd structure" unless buf.size == 0 end |
#read_from_stream(io) ⇒ Object
:nodoc:
918 919 920 921 |
# File 'lib/rant/archive/rubyzip.rb', line 918 def read_from_stream(io) #:nodoc: read_e_o_c_d(io) read_central_directory_entries(io) end |
#size ⇒ Object
Returns the number of entries in the central directory (and consequently in the zip archive).
948 949 950 |
# File 'lib/rant/archive/rubyzip.rb', line 948 def size @entrySet.size end |
#write_to_stream(io) ⇒ Object
:nodoc:
867 868 869 870 871 |
# File 'lib/rant/archive/rubyzip.rb', line 867 def write_to_stream(io) #:nodoc: offset = io.tell @entrySet.each { |entry| entry.write_c_dir_entry(io) } write_e_o_c_d(io, offset) end |