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