Class: Omnizip::Formats::Rar::ArchiveVerifier
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::ArchiveVerifier
- 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
-
#archive_path ⇒ Object
readonly
Returns the value of attribute archive_path.
-
#parity_handler ⇒ Object
readonly
Returns the value of attribute parity_handler.
-
#recovery_record ⇒ Object
readonly
Returns the value of attribute recovery_record.
Instance Method Summary collapse
-
#initialize(archive_path) ⇒ ArchiveVerifier
constructor
Initialize verifier.
-
#quick_test ⇒ Boolean
Quick test of archive.
-
#verify(use_recovery: true, verbose: false) ⇒ VerificationResult
Verify archive integrity.
-
#verify_entry(entry, verbose = false) ⇒ Boolean
Verify single file entry.
Constructor Details
#initialize(archive_path) ⇒ ArchiveVerifier
Initialize verifier
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_path ⇒ Object (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_handler ⇒ Object (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_record ⇒ Object (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_test ⇒ Boolean
Quick test of archive
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
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.}" end result end |
#verify_entry(entry, verbose = false) ⇒ Boolean
Verify single file entry
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.})" if verbose false end |