Class: Cabriolet::CAB::CommandHandler

Inherits:
Cabriolet::Commands::BaseCommandHandler show all
Defined in:
lib/cabriolet/cab/command_handler.rb

Overview

Command handler for CAB (Microsoft Cabinet) format

This handler implements the unified command interface for CAB files, wrapping the existing CAB::Decompressor and CAB::Compressor classes.

Instance Method Summary collapse

Methods inherited from Cabriolet::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 a new CAB archive

Creates a cabinet file from the specified source files.

Options Hash (options):

  • :compression (String, Symbol)

    Compression type (:none, :mszip, :lzx, :quantum)

Raises:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cabriolet/cab/command_handler.rb', line 68

def create(output, files = [], options = {})
  raise ArgumentError, "No files specified" if files.empty?

  files.each do |f|
    raise ArgumentError, "File does not exist: #{f}" unless File.exist?(f)
  end

  compression = parse_compression_option(options[:compression])

  compressor = Compressor.new
  files.each { |f| compressor.add_file(f) }

  puts "Creating #{output} with #{files.size} file(s) (#{compression} compression)" if verbose?
  bytes = compressor.generate(output, compression: compression)
  puts "Created #{output} (#{bytes} bytes, #{files.size} files)"
end

#extract(file, output_dir = nil, options = {}) ⇒ void

This method returns an undefined value.

Extract files from CAB archive

Extracts all files from the cabinet to the specified output directory. Supports salvage mode for corrupted archives.

Options Hash (options):

  • :salvage (Boolean)

    Enable salvage mode for corrupted files



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cabriolet/cab/command_handler.rb', line 43

def extract(file, output_dir = nil, options = {})
  validate_file_exists(file)

  output_dir ||= "."
  output_dir = ensure_output_dir(output_dir)

  decompressor = Decompressor.new
  decompressor.salvage = true if options[:salvage]

  cabinet = decompressor.open(file)
  count = decompressor.extract_all(cabinet, output_dir)

  puts "Extracted #{count} file(s) to #{output_dir}"
end

#info(file, _options = {}) ⇒ void

This method returns an undefined value.

Display detailed CAB file information

Shows comprehensive information about the cabinet structure, including folders, files, and attributes.



93
94
95
96
97
98
99
100
# File 'lib/cabriolet/cab/command_handler.rb', line 93

def info(file, _options = {})
  validate_file_exists(file)

  decompressor = Decompressor.new
  cabinet = decompressor.open(file)

  display_cabinet_info(cabinet)
end

#list(file, _options = {}) ⇒ void

This method returns an undefined value.

List CAB file contents

Displays information about the cabinet including set ID, file count, and lists all contained files with their sizes.



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

def list(file, _options = {})
  validate_file_exists(file)

  decompressor = Decompressor.new
  cabinet = decompressor.open(file)

  display_header(cabinet)
  display_files(cabinet.files)
end

#test(file, _options = {}) ⇒ void

This method returns an undefined value.

Test CAB file integrity

Verifies the integrity of the cabinet file structure. Note: Full integrity testing is not yet implemented.



110
111
112
113
114
115
116
117
118
119
# File 'lib/cabriolet/cab/command_handler.rb', line 110

def test(file, _options = {})
  validate_file_exists(file)

  decompressor = Decompressor.new
  cabinet = decompressor.open(file)

  puts "Testing #{cabinet.filename}..."
  # TODO: Implement full integrity testing
  puts "OK: All #{cabinet.file_count} files passed integrity check"
end