Class: Cabriolet::KWAJ::CommandHandler
- Inherits:
-
Commands::BaseCommandHandler
- Object
- Commands::BaseCommandHandler
- Cabriolet::KWAJ::CommandHandler
- Defined in:
- lib/cabriolet/kwaj/command_handler.rb
Overview
Command handler for KWAJ compressed format
This handler implements the unified command interface for KWAJ files, wrapping the existing KWAJ::Decompressor and KWAJ::Compressor classes.
Instance Method Summary collapse
-
#create(output, files = [], options = {}) ⇒ void
Create KWAJ compressed file.
-
#extract(file, output_dir = nil, options = {}) ⇒ void
Extract KWAJ compressed file.
-
#info(file, _options = {}) ⇒ void
Display detailed KWAJ file information.
-
#list(file, _options = {}) ⇒ void
List KWAJ file information.
-
#test(file, _options = {}) ⇒ void
Test KWAJ file integrity.
Methods inherited from Commands::BaseCommandHandler
Constructor Details
This class inherits a constructor from Cabriolet::Commands::BaseCommandHandler
Instance Method Details
#create(output, files = [], options = {}) ⇒ void
This method returns an undefined value.
Create KWAJ compressed file
Compresses a file using KWAJ compression.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/cabriolet/kwaj/command_handler.rb', line 84 def create(output, files = [], = {}) raise ArgumentError, "No file specified" if files.empty? if files.size > 1 raise ArgumentError, "KWAJ format supports only one file at a time" end file = files.first unless File.exist?(file) raise ArgumentError, "File does not exist: #{file}" end compression = parse_compression_option([:compression]) = { compression: compression } [:include_length] = true if [:include_length] [:filename] = [:filename] if [:filename] if [:extra_data] [:extra_data] = [:extra_data] end # Auto-generate output name if not provided if output.nil? output = "#{file}.kwj" end compressor = Compressor.new puts "Compressing #{file} -> #{output} (#{compression} compression)" if verbose? bytes = compressor.compress(file, output, **) puts "Compressed #{file} to #{output} (#{bytes} bytes, #{compression} compression)" end |
#extract(file, output_dir = nil, options = {}) ⇒ void
This method returns an undefined value.
Extract KWAJ compressed file
Extracts/decompresses the KWAJ file to its original form. Auto-detects output filename if not specified.
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 |
# File 'lib/cabriolet/kwaj/command_handler.rb', line 44 def extract(file, output_dir = nil, = {}) validate_file_exists(file) output = [:output] # Auto-detect output name if not provided if output.nil? && output_dir.nil? output = auto_output_filename(file) end # If output_dir is specified, ensure it exists and construct output path if output.nil? && output_dir output_dir = ensure_output_dir(output_dir) base_name = File.basename(file, ".*") output = File.join(output_dir, base_name) end decompressor = Decompressor.new header = decompressor.open(file) puts "Extracting #{file} -> #{output}" if verbose? bytes = decompressor.extract(header, file, output) decompressor.close(header) puts "Extracted #{file} to #{output} (#{bytes} bytes)" end |
#info(file, _options = {}) ⇒ void
This method returns an undefined value.
Display detailed KWAJ file information
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/cabriolet/kwaj/command_handler.rb', line 126 def info(file, = {}) validate_file_exists(file) decompressor = Decompressor.new header = decompressor.open(file) display_kwaj_info(header, file) decompressor.close(header) end |
#list(file, _options = {}) ⇒ void
This method returns an undefined value.
List KWAJ file information
For KWAJ files, list displays detailed file information rather than a file listing (single file archive).
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cabriolet/kwaj/command_handler.rb', line 23 def list(file, = {}) validate_file_exists(file) decompressor = Decompressor.new header = decompressor.open(file) display_kwaj_info(header, file) decompressor.close(header) end |
#test(file, _options = {}) ⇒ void
This method returns an undefined value.
Test KWAJ file integrity
Verifies the KWAJ file structure.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/cabriolet/kwaj/command_handler.rb', line 144 def test(file, = {}) validate_file_exists(file) decompressor = Decompressor.new header = decompressor.open(file) puts "Testing #{file}..." # TODO: Implement full integrity testing puts "OK: KWAJ file structure is valid" puts "Compression: #{header.compression_name}" puts "Data offset: #{header.data_offset} bytes" puts "Uncompressed size: #{header.length || 'unknown'} bytes" decompressor.close(header) end |