Class: Zipping::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/zipping.rb

Instance Method Summary collapse

Constructor Details

#initialize(output_stream, file_division_size) ⇒ Writer

Returns a new instance of Writer.

Raises:



271
272
273
274
275
276
277
278
279
# File 'lib/zipping.rb', line 271

def initialize(output_stream, file_division_size)
  @output_stream = output_stream
  raise Error, 'Specified output stream does not support `<<\' method.' unless @output_stream.respond_to? :<<
  @o = StreamMeter.new output_stream
  @s = file_division_size
  raise Error, 'Bad file_division_size' unless @s.is_a?(Integer) && @s > 0
  @dps = []
  @entries = []
end

Instance Method Details

#closeObject



311
312
313
314
315
316
317
318
319
# File 'lib/zipping.rb', line 311

def close
  # start of central directories
  @header_offset = current_position
  write_central_dir_headers

  # total size of central directories
  @header_size = current_position - @header_offset
  write_end_central_dir_header
end

#load_entity(entity) ⇒ Object

Data interface



283
284
285
286
# File 'lib/zipping.rb', line 283

def load_entity(entity)
  @fixed_entity = entity
  @entries << entity[:zip_path]
end

#path_exists?(abs_path) ⇒ Boolean

Returns:

  • (Boolean)


288
289
290
# File 'lib/zipping.rb', line 288

def path_exists?(abs_path)
  @entries.include? abs_path
end

#write_directory_entryObject



303
304
305
# File 'lib/zipping.rb', line 303

def write_directory_entry
  write_entry_without_compress '', :dir
end

#write_file_entryObject

Write operations



294
295
296
297
298
299
300
301
# File 'lib/zipping.rb', line 294

def write_file_entry
  write_entry do |path, filetime, name|
    write PKHeader.pk0304(filetime, name.length, true).pack('VvvvvvVVVvv'), name
    ret = deflate_file path
    write PKHeader.pk0708(ret[:crc], ret[:complen], ret[:uncomplen]).pack('VVVV')
    ret
  end
end

#write_symbolic_link_entryObject



307
308
309
# File 'lib/zipping.rb', line 307

def write_symbolic_link_entry
  write_entry_without_compress File.readlink(@fixed_entity[:path]), :symlink
end