2019-10-03 09:19:35 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Compression
|
|
|
|
class Pipeline < Strategy
|
|
|
|
def initialize(strategies)
|
|
|
|
@strategies = strategies
|
|
|
|
end
|
|
|
|
|
|
|
|
def extension
|
|
|
|
@strategies.reduce('') { |ext, strategy| ext += strategy.extension }
|
|
|
|
end
|
|
|
|
|
|
|
|
def compress(path, target_name)
|
|
|
|
current_target = target_name
|
|
|
|
@strategies.reduce('') do |compressed_path, strategy|
|
|
|
|
compressed_path = strategy.compress(path, current_target)
|
|
|
|
current_target = compressed_path.split('/').last
|
|
|
|
|
|
|
|
compressed_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-29 14:00:38 -04:00
|
|
|
def decompress(dest_path, compressed_file_path, max_size)
|
2019-10-09 10:41:16 -04:00
|
|
|
@strategies.reverse.reduce(compressed_file_path) do |to_decompress, strategy|
|
2022-09-29 14:00:38 -04:00
|
|
|
next_compressed_file = strategy.decompress(dest_path, to_decompress, max_size)
|
|
|
|
FileUtils.rm_rf(to_decompress)
|
|
|
|
next_compressed_file
|
2019-10-03 09:19:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|