Class: Omnizip::Formats::Rar::ArchiveVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/formats/rar/archive_verifier.rb

Overview

RAR archive verification Verifies archive integrity using CRCs and recovery records

Defined Under Namespace

Classes: VerificationResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive_path) ⇒ ArchiveVerifier

Initialize verifier

Parameters:

  • archive_path (String)

    Path to RAR archive



60
61
62
63
64
# File 'lib/omnizip/formats/rar/archive_verifier.rb', line 60

def initialize(archive_path)
  @archive_path = archive_path
  @recovery_record = nil
  @parity_handler = nil
end

Instance Attribute Details

#archive_pathObject (readonly)

Returns the value of attribute archive_path.



9
10
11
# File 'lib/omnizip/formats/rar/archive_verifier.rb', line 9

def archive_path
  @archive_path
end

#parity_handlerObject (readonly)

Returns the value of attribute parity_handler.



9
10
11
# File 'lib/omnizip/formats/rar/archive_verifier.rb', line 9

def parity_handler
  @parity_handler
end

#recovery_recordObject (readonly)

Returns the value of attribute recovery_record.



9
10
11
# File 'lib/omnizip/formats/rar/archive_verifier.rb', line 9

def recovery_record
  @recovery_record
end

Instance Method Details

#quick_testBoolean

Quick test of archive

Returns:

  • (Boolean)

    true if archive can be opened



132
133
134
135
136
137
# File 'lib/omnizip/formats/rar/archive_verifier.rb', line 132

def quick_test
  Reader.new(@archive_path).open
  true
rescue StandardError
  false
end

#verify(use_recovery: true, verbose: false) ⇒ VerificationResult

Verify archive integrity

Parameters:

  • use_recovery (Boolean) (defaults to: true)

    Use recovery records for verification

  • verbose (Boolean) (defaults to: false)

    Enable verbose output

Returns:



71
72
73
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
107
# File 'lib/omnizip/formats/rar/archive_verifier.rb', line 71

def verify(use_recovery: true, verbose: false)
  result = VerificationResult.new

  begin
    # Open and parse archive
    reader = Reader.new(@archive_path)
    reader.open

    result.files_total = reader.entries.size

    # Detect recovery records
    detect_recovery_records(reader, result) if use_recovery

    # Verify each file
    reader.entries.each do |entry|
      file_valid = verify_entry(entry, verbose)

      if file_valid
        result.files_ok += 1
      else
        result.files_corrupted += 1
        result.corrupted_files << entry.name
        result.valid = false
      end
    end

    # Check if corruption is recoverable
    if result.files_corrupted.positive? && result.recovery_available
      result.recoverable = check_recoverability(result.corrupt_blocks)
    end
  rescue StandardError => e
    result.valid = false
    result.errors << "Verification failed: #{e.message}"
  end

  result
end

#verify_entry(entry, verbose = false) ⇒ Boolean

Verify single file entry

Parameters:

  • entry (Models::RarEntry)

    Entry to verify

  • verbose (Boolean) (defaults to: false)

    Print verbose output

Returns:

  • (Boolean)

    true if valid



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/omnizip/formats/rar/archive_verifier.rb', line 114

def verify_entry(entry, verbose = false)
  return true if entry.directory?

  # For now, we rely on the decompressor to verify
  # In a full implementation, we would check CRC32
  valid = verify_entry_crc(entry)

  puts "#{entry.name}: #{valid ? 'OK' : 'FAILED'}" if verbose

  valid
rescue StandardError => e
  puts "#{entry.name}: ERROR (#{e.message})" if verbose
  false
end