Class: ZipTricks::StoredSizeEstimator
- Inherits:
-
Struct
- Object
- Struct
- ZipTricks::StoredSizeEstimator
- Defined in:
- lib/zip_tricks/stored_size_estimator.rb
Overview
Helps to estimate archive sizes
Instance Attribute Summary collapse
-
#manifest ⇒ Object
Returns the value of attribute manifest.
Class Method Summary collapse
-
.perform_fake_archiving {|StoredSizeEstimator| ... } ⇒ Fixnum
Performs the estimate using fake archiving.
Instance Method Summary collapse
-
#add_compressed_entry(name, size_uncompressed, size_compressed) ⇒ 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) ⇒ Object
Add a fake entry to the archive, to see how big it is going to be in the end.
Instance Attribute Details
#manifest ⇒ Object
Returns the value of attribute manifest
2 3 4 |
# File 'lib/zip_tricks/stored_size_estimator.rb', line 2 def manifest @manifest end |
Class Method Details
.perform_fake_archiving {|StoredSizeEstimator| ... } ⇒ Fixnum
Performs the estimate using fake archiving. It needs to know the sizes of the entries upfront. Usage:
expected_zip_size = StoredSizeEstimator.perform_fake_archiving do | estimator |
estimator.add_stored_entry("file.doc", size=898291)
estimator.add_compressed_entry("family.tif", size=89281911, compressed_size=121908)
end
14 15 16 17 18 19 20 21 22 |
# File 'lib/zip_tricks/stored_size_estimator.rb', line 14 def self.perform_fake_archiving _, bytes = ZipTricks::Manifest.build do |manifest| # The API for this class uses positional arguments. The Manifest API # uses keyword arguments. call_adapter = new(manifest) yield(call_adapter) end bytes end |
Instance Method Details
#add_compressed_entry(name, size_uncompressed, size_compressed) ⇒ Object
Add a fake entry to the archive, to see how big it is going to be in the end.
40 41 42 43 |
# File 'lib/zip_tricks/stored_size_estimator.rb', line 40 def add_compressed_entry(name, size_uncompressed, size_compressed) manifest.add_compressed_entry(name: name, size_uncompressed: size_uncompressed, size_compressed: size_compressed) self end |
#add_stored_entry(name, size_uncompressed) ⇒ Object
Add a fake entry to the archive, to see how big it is going to be in the end.
29 30 31 32 |
# File 'lib/zip_tricks/stored_size_estimator.rb', line 29 def add_stored_entry(name, size_uncompressed) manifest.add_stored_entry(name: name, size_uncompressed: size_uncompressed) self end |