Class: Omnizip::Converter::ZipToSevenZipStrategy
- Inherits:
-
ConversionStrategy
- Object
- ConversionStrategy
- Omnizip::Converter::ZipToSevenZipStrategy
- Defined in:
- lib/omnizip/converter/zip_to_seven_zip_strategy.rb
Overview
Convert ZIP archives to 7-Zip format
Instance Attribute Summary
Attributes inherited from ConversionStrategy
#options, #source_path, #target_path
Class Method Summary collapse
-
.can_convert?(source, target) ⇒ Boolean
Check if can convert.
Instance Method Summary collapse
-
#convert ⇒ ConversionResult
Perform ZIP to 7z conversion.
-
#source_format ⇒ Symbol
Get source format.
-
#target_format ⇒ Symbol
Get target format.
Methods inherited from ConversionStrategy
Constructor Details
This class inherits a constructor from Omnizip::Converter::ConversionStrategy
Class Method Details
.can_convert?(source, target) ⇒ Boolean
Check if can convert
50 51 52 |
# File 'lib/omnizip/converter/zip_to_seven_zip_strategy.rb', line 50 def self.can_convert?(source, target) source.end_with?(".zip") && target.end_with?(".7z") end |
Instance Method Details
#convert ⇒ ConversionResult
Perform ZIP to 7z conversion
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/omnizip/converter/zip_to_seven_zip_strategy.rb', line 11 def convert start_time = Time.now entry_count = 0 Dir.mktmpdir("omnizip_convert_zip") do |tmp| # Extract the ZIP through the native reader; directories are # implied by extracted file paths Omnizip::Formats::Zip.extract(source_path, tmp) writer = Omnizip::Formats::SevenZip::Writer.new(target_path, ) Dir.glob(File.join(tmp, "**", "*")).each do |path| next if File.directory?(path) entry_count += 1 writer.add_file(path, path.delete_prefix("#{tmp}/")) end writer.write end create_result(start_time, entry_count) end |
#source_format ⇒ Symbol
Get source format
36 37 38 |
# File 'lib/omnizip/converter/zip_to_seven_zip_strategy.rb', line 36 def source_format :zip end |
#target_format ⇒ Symbol
Get target format
42 43 44 |
# File 'lib/omnizip/converter/zip_to_seven_zip_strategy.rb', line 42 def target_format :seven_zip end |