Class: Omnizip::Commands::DecompressCommand
- Inherits:
-
Object
- Object
- Omnizip::Commands::DecompressCommand
- Defined in:
- lib/omnizip/commands/decompress_command.rb
Overview
Command to decompress files using specified algorithm.
Constant Summary collapse
- ARCHIVE_EXTENSIONS =
%w[.zip .7z .tar .rar .cpio .iso].freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ DecompressCommand
constructor
Initialize decompress command with options.
-
#run(input_file, output_file) ⇒ void
Execute the decompress command.
Constructor Details
#initialize(options = {}) ⇒ DecompressCommand
Initialize decompress command with options.
30 31 32 |
# File 'lib/omnizip/commands/decompress_command.rb', line 30 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
25 26 27 |
# File 'lib/omnizip/commands/decompress_command.rb', line 25 def @options end |
Instance Method Details
#run(input_file, output_file) ⇒ void
This method returns an undefined value.
Execute the decompress command.
Archives (.zip/.7z/.tar/...) extract into the output directory; single-file streams decompress to the output file.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/omnizip/commands/decompress_command.rb', line 42 def run(input_file, output_file) validate_inputs(input_file, output_file) if archive_input?(input_file) || File.directory?(output_file) run_archive_extract(input_file, output_file) return end algorithm_name = [:algorithm] || detect_algorithm verbose = [:verbose] || false CliOutputFormatter.verbose_puts( "Decompressing #{input_file} to #{output_file}...", verbose, ) CliOutputFormatter.verbose_puts( "Algorithm: #{algorithm_name}", verbose, ) start_time = Time.now decompress_file(input_file, output_file, algorithm_name) elapsed = Time.now - start_time input_size = File.size(input_file) output_size = File.size(output_file) if verbose puts "" puts CliOutputFormatter.format_compression_stats( output_size, input_size, elapsed, ) else puts "Decompressed: #{input_file} -> #{output_file}" end end |