Class: ZipTricks::Manifest
- Inherits:
-
Struct
- Object
- Struct
- ZipTricks::Manifest
- Defined in:
- lib/zip_tricks/manifest.rb
Overview
Helps to estimate archive sizes
Defined Under Namespace
Classes: ZipSpan
Instance Attribute Summary collapse
-
#io ⇒ Object
Returns the value of attribute io.
-
#part_list ⇒ Object
Returns the value of attribute part_list.
-
#zip_streamer ⇒ Object
Returns the value of attribute zip_streamer.
Class Method Summary collapse
-
.build {|Manifest| ... } ⇒ Array<ZipSpan>, Fixnum
Builds an array of spans within the ZIP file and computes the size of the resulting archive in bytes.
Instance Method Summary collapse
-
#add_compressed_entry(name:, size_uncompressed:, size_compressed:, segment_info: nil) ⇒ Object
Add a fake entry to the archive, to see how big it is going to be in the end.
-
#add_stored_entry(name:, size_uncompressed:, segment_info: nil) ⇒ Object
Add a fake entry to the archive, to see how big it is going to be in the end.
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io
2 3 4 |
# File 'lib/zip_tricks/manifest.rb', line 2 def io @io end |
#part_list ⇒ Object
Returns the value of attribute part_list
2 3 4 |
# File 'lib/zip_tricks/manifest.rb', line 2 def part_list @part_list end |
#zip_streamer ⇒ Object
Returns the value of attribute zip_streamer
2 3 4 |
# File 'lib/zip_tricks/manifest.rb', line 2 def zip_streamer @zip_streamer end |
Class Method Details
.build {|Manifest| ... } ⇒ Array<ZipSpan>, Fixnum
Builds an array of spans within the ZIP file and computes the size of the resulting archive in bytes.
zip_spans, bytesize = Manifest.build do | b |
b.add_stored_entry(name: "file.doc", size: 898291)
b.add_compressed_entry(name: "family.tif", size: 89281911, compressed_size: 121908)
end
bytesize #=> ... (Fixnum or Bignum)
zip_spans[0] #=> Manifest::ZipSpan(part_type: :entry_header, byte_range_in_zip: 0..44, ...)
zip_spans[-1] #=> Manifest::ZipSpan(part_type: :central_directory, byte_range_in_zip: 776721..898921, ...)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/zip_tricks/manifest.rb', line 20 def self.build output_io = ZipTricks::WriteAndTell.new(ZipTricks::NullWriter) part_list = [] last_range_end = 0 ZipTricks::Streamer.open(output_io) do | zip_streamer | manifest = new(zip_streamer, output_io, part_list) yield(manifest) last_range_end = part_list[-1].byte_range_in_zip.end end # Record the position of the central directory directory_location = (last_range_end + 1)..(output_io.tell - 1) part_list << ZipSpan.new(:central_directory, directory_location, :central_directory, nil) [part_list, output_io.tell] end |
Instance Method Details
#add_compressed_entry(name:, size_uncompressed:, size_compressed:, segment_info: nil) ⇒ Object
Add a fake entry to the archive, to see how big it is going to be in the end.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/zip_tricks/manifest.rb', line 64 def add_compressed_entry(name:, size_uncompressed:, size_compressed:, segment_info: nil) register_part(:entry_header, name, segment_info) do zip_streamer.add_compressed_entry(name, size_uncompressed, C_fake_crc, size_compressed) end register_part(:entry_body, name, segment_info) do zip_streamer.simulate_write(size_compressed) end self end |
#add_stored_entry(name:, size_uncompressed:, segment_info: nil) ⇒ Object
Add a fake entry to the archive, to see how big it is going to be in the end.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/zip_tricks/manifest.rb', line 44 def add_stored_entry(name:, size_uncompressed:, segment_info: nil) register_part(:entry_header, name, segment_info) do zip_streamer.add_stored_entry(name, size_uncompressed, C_fake_crc) end register_part(:entry_body, name, segment_info) do zip_streamer.simulate_write(size_uncompressed) end self end |