Class: Omnizip::Commands::ParityVerifyCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/commands/parity_verify_command.rb

Overview

Command to verify files using PAR2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(par2_file, options = {}) ⇒ ParityVerifyCommand

Initialize command

Parameters:

  • par2_file (String)

    Path to .par2 index file

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

    Command options



17
18
19
20
# File 'lib/omnizip/commands/parity_verify_command.rb', line 17

def initialize(par2_file, options = {})
  @par2_file = par2_file
  @options = default_options.merge(options)
end

Instance Attribute Details

#optionsHash (readonly)

Returns Command options.

Returns:

  • (Hash)

    Command options



11
12
13
# File 'lib/omnizip/commands/parity_verify_command.rb', line 11

def options
  @options
end

#par2_fileString (readonly)

Returns PAR2 file path.

Returns:

  • (String)

    PAR2 file path



8
9
10
# File 'lib/omnizip/commands/parity_verify_command.rb', line 8

def par2_file
  @par2_file
end

Instance Method Details

#runInteger

Execute command

Returns:

  • (Integer)

    Exit code (0 if all OK, 1 if damage, 2 if error)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/omnizip/commands/parity_verify_command.rb', line 25

def run
  validate_inputs!

  puts "Verifying files with PAR2: #{File.basename(@par2_file)}"
  puts

  result = Parity.verify(@par2_file)

  display_results(result)

  # Exit code based on results
  if result.all_ok?
    0
  elsif result.repairable?
    1 # Damage but repairable
  else
    2 # Damage not repairable
  end
rescue StandardError => e
  report_error(e)
  2
end