Class: CompareCompressors::Comparer
- Inherits:
-
Object
- Object
- CompareCompressors::Comparer
- Defined in:
- lib/compare_compressors/comparer.rb
Overview
Run compressors on targets and record the results.
The general approach is, for each target:
-
Copy the original target (read only) to a temporary folder (read write); the copy is the ‘work target’.
-
Hash the work target so we can make sure we don’t change it.
-
For each compressor and level, compress the work target.
-
Remove the work target (if the compressor left it)
-
Decompress the compressed target; this should restore the work target.
-
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
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 |