Class: Cabriolet::SZDD::CommandHandler

Inherits:
Commands::BaseCommandHandler show all
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

Methods inherited from Commands::BaseCommandHandler

#initialize

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.

Parameters:

  • output (String)

    Output SZDD file path

  • files (Array<String>) (defaults to: [])

    Input file (single file for SZDD)

  • options (Hash) (defaults to: {})

    Additional options

Options Hash (options):

  • :missing_char (String)

    Missing character for filename

  • :szdd_format (String)

    SZDD format (:normal, :qbasic)

Raises:



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 = [], options = {})
  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(options[:szdd_format])
  compress_options = { format: format }
  if options[:missing_char]
    compress_options[:missing_char] =
      options[: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, **compress_options)

  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.

Parameters:

  • file (String)

    Path to the SZDD file

  • output (String, nil) (defaults to: nil)

    Output file path (or directory, for single-file extraction)

  • options (Hash) (defaults to: {})

    Additional options

Options Hash (options):

  • :output (String)

    Output file path



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, options = {})
  validate_file_exists(file)

  # Use output file from options if specified, otherwise use positional argument
  output ||= options[: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

Parameters:

  • file (String)

    Path to the SZDD file

  • options (Hash)

    Additional options (unused)



113
114
115
116
117
118
119
120
121
122
# File 'lib/cabriolet/szdd/command_handler.rb', line 113

def info(file, _options = {})
  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).

Parameters:

  • file (String)

    Path to the SZDD file

  • options (Hash)

    Additional options (unused)



23
24
25
26
27
28
29
30
31
32
# File 'lib/cabriolet/szdd/command_handler.rb', line 23

def list(file, _options = {})
  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.

Parameters:

  • file (String)

    Path to the SZDD file

  • options (Hash)

    Additional options (unused)



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, _options = {})
  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