Harbor Documentation

Harbor::ZippedIO::ZipCentralDirectory

Constants

  • DEFLATED
  • FSTYPE_UNIX

Public Class Methods

new(entries, offset)

       # File lib/harbor/zipped_io.rb, line 109
109:       def initialize(entries, offset)
110:         @entries = entries
111:         @offset = offset
112:       end

Public Instance Methods

read()

       # File lib/harbor/zipped_io.rb, line 114
114:       def read
115:         generate unless @io
116: 
117:         @io.pos = 0
118:         while data = @io.read(Harbor::ZippedIO::block_size)
119:           yield data
120:         end
121:       end

size()

       # File lib/harbor/zipped_io.rb, line 123
123:       def size
124:         generate unless @io
125:         @io.size
126:       end

Private Instance Methods

binary_dos_date()

       # File lib/harbor/zipped_io.rb, line 130
130:       def binary_dos_date
131:         (time.day) + (time.month << 5) + ((time.year - 1980) << 9)
132:       end

binary_dos_time()

       # File lib/harbor/zipped_io.rb, line 134
134:       def binary_dos_time
135:         (time.sec / 2) + (time.min << 5) + (time.hour << 11)
136:       end

generate()

       # File lib/harbor/zipped_io.rb, line 138
138:       def generate
139:         @io = StringIO.new
140: 
141:         size = 0
142: 
143:         unix_permissions = 0644
144:         external_file_attributes = (FSTYPE_UNIX << 12 | (unix_permissions & 07777)) << 16
145: 
146:         @entries.each do |entry|
147:           data = [
148:             CENTRAL_DIRECTORY_ENTRY_SIGNATURE,
149:             0, # version
150:             FSTYPE_UNIX,
151:             0,
152:             0,
153:             DEFLATED,
154:             binary_dos_time,
155:             binary_dos_date,
156:             entry.crc,
157:             entry.compressed_size,
158:             entry.uncompressed_size,
159:             entry.name.length,
160:             0, # extra length
161:             0, # comment length
162:             0, # disk number start
163:             1, # internal file attributes
164:             external_file_attributes,
165:             entry.local_header_offset,
166:             entry.name,
167:             '', #extra
168:             '' #comment
169:           ].pack('VCCvvvvvVVVvvvvvVV') << entry.name << ""
170:           size += data.size
171:           @io << data
172:         end
173: 
174:         @io << [
175:           END_OF_CENTRAL_DIRECTORY_SIGNATURE,
176:           0, # number of this disk
177:           0, # numer of disk with start of central directory
178:           @entries.size,
179:           @entries.size,
180:           @entries.inject(0) { |value, entry| entry.central_directory_header_size + value },
181:           # size,
182:           @offset,
183:           0 # comment length
184:         ].pack('VvvvvVVv')
185:         @io << "" #comment
186:       end

time()

       # File lib/harbor/zipped_io.rb, line 188
188:       def time
189:         @time ||= Time.now
190:       end