Class: CompareCompressors::Comparer

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

Overview

Run compressors on targets and record the results.

The general approach is, for each target:

  1. Copy the original target (read only) to a temporary folder (read write); the copy is the ‘work target’.

  2. Hash the work target so we can make sure we don’t change it.

  3. For each compressor and level, compress the work target.

  4. Remove the work target (if the compressor left it)

  5. Decompress the compressed target; this should restore the work target.

  6. Check the work target’s hash before we start the next compressor or level, to make sure the compression hasn’t broken it somehow.

This approach is a bit complicated, but it lets us (1) make sure we don’t change the original targets, since they’re copied, (2) make sure we don’t accidentally change the work target during the run, which would invalidate the results, and (3) avoid copying the work target from the target repeatedly.

Instance Method Summary collapse

Instance Method Details

#run(csv, compressors, targets) ⇒ Object

Parameters:

  • csv (CSV)

    CSV writer for output

  • compressors (Array<Compressor>)
  • targets (Array<String>)

    pathnames of targets (read only)



34
35
36
37
38
39
40
41
42
43
# File 'lib/compare_compressors/comparer.rb', line 34

def run(csv, compressors, targets)
  csv << Result.members
  targets.each do |target|
    Dir.mktmpdir do |tmp|
      work_target = stage_target(tmp, target)
      evaluate_target(csv, compressors, target, work_target)
    end
  end
  nil
end