Class: Cabriolet::SZDD::CommandHandler
- Inherits:
-
Commands::BaseCommandHandler
- Object
- Commands::BaseCommandHandler
- Cabriolet::SZDD::CommandHandler
- Defined in:
- lib/cabriolet/szdd/command_handler.rb
Overview
Command handler for SZDD (LZSS-compressed) format
This handler implements the unified command interface for SZDD files, wrapping the existing SZDD::Decompressor and SZDD::Compressor classes.
Instance Method Summary collapse
-
#create(output, files = [], options = {}) ⇒ void
Create SZDD compressed file.
-
#extract(file, output = nil, options = {}) ⇒ void
Extract SZDD compressed file.
-
#info(file, _options = {}) ⇒ void
Display detailed SZDD file information.
-
#list(file, _options = {}) ⇒ void
List SZDD file information.
-
#test(file, _options = {}) ⇒ void
Test SZDD 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 SZDD compressed file
Compresses a file using SZDD (LZSS) compression.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/cabriolet/szdd/command_handler.rb', line 74 def create(output, files = [], = {}) raise ArgumentError, "No file specified" if files.empty? if files.size > 1 raise ArgumentError, "SZDD format supports only one file at a time" end file = files.first unless File.exist?(file) raise ArgumentError, "File does not exist: #{file}" end format = parse_format_option([:szdd_format]) = { format: format } if [:missing_char] [:missing_char] = [:missing_char] end # Auto-generate output name if not provided if output.nil? output = auto_generate_output(file) end compressor = Compressor.new puts "Compressing #{file} -> #{output}" if verbose? bytes = compressor.compress(file, output, **) puts "Compressed #{file} to #{output} (#{bytes} bytes)" end |
#extract(file, output = nil, options = {}) ⇒ void
This method returns an undefined value.
Extract SZDD compressed file
Expands the SZDD 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 |
# File 'lib/cabriolet/szdd/command_handler.rb', line 44 def extract(file, output = nil, = {}) validate_file_exists(file) # Use output file from options if specified, otherwise use positional argument output ||= [:output] # Auto-detect output name if not provided output ||= auto_output_filename(file) decompressor = Decompressor.new header = decompressor.open(file) puts "Expanding #{file} -> #{output}" if verbose? bytes = decompressor.extract(header, output) decompressor.close(header) puts "Expanded #{file} to #{output} (#{bytes} bytes)" end |
#info(file, _options = {}) ⇒ void
This method returns an undefined value.
Display detailed SZDD file information
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/cabriolet/szdd/command_handler.rb', line 113 def info(file, = {}) validate_file_exists(file) decompressor = Decompressor.new header = decompressor.open(file) display_szdd_info(header, file) decompressor.close(header) end |
#list(file, _options = {}) ⇒ void
This method returns an undefined value.
List SZDD file information
For SZDD 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/szdd/command_handler.rb', line 23 def list(file, = {}) validate_file_exists(file) decompressor = Decompressor.new header = decompressor.open(file) display_szdd_info(header, file) decompressor.close(header) end |
#test(file, _options = {}) ⇒ void
This method returns an undefined value.
Test SZDD file integrity
Verifies the SZDD file structure.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/cabriolet/szdd/command_handler.rb', line 131 def test(file, = {}) validate_file_exists(file) decompressor = Decompressor.new header = decompressor.open(file) puts "Testing #{file}..." # TODO: Implement full integrity testing puts "OK: SZDD file structure is valid" puts "Format: #{header.format.to_s.upcase}" puts "Uncompressed size: #{header.length} bytes" decompressor.close(header) end |