Class: ZipTricks::StoredSizeEstimator

Inherits:
Struct
  • Object
show all
Defined in:
lib/zip_tricks/stored_size_estimator.rb

Overview

Helps to estimate archive sizes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#manifestObject

Returns the value of attribute manifest

Returns:

  • (Object)

    the current value of 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

Yields:

Returns:

  • (Fixnum)

    the size of the resulting archive, in bytes



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.

Parameters:

  • name (String)

    the name of the file (filenames are variable-width in the ZIP)

  • size_uncompressed (Fixnum)

    size of the uncompressed entry

  • size_compressed (Fixnum)

    size of the compressed entry

Returns:

  • self



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.

Parameters:

  • name (String)

    the name of the file (filenames are variable-width in the ZIP)

  • size_uncompressed (Fixnum)

    size of the uncompressed entry

Returns:

  • self



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