Class: Omnizip::Formats::Rar::VolumeManager

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

Overview

Manages multi-volume RAR archives Handles volume detection, sequencing, and coordination

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ VolumeManager

Initialize volume manager

Parameters:

  • path (String)

    Path to any volume in the set



14
15
16
17
18
# File 'lib/omnizip/formats/rar/volume_manager.rb', line 14

def initialize(path)
  @base_path = path
  @volumes = []
  detect_volumes
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



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

def base_path
  @base_path
end

#volumesObject (readonly)

Returns the value of attribute volumes.



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

def volumes
  @volumes
end

Instance Method Details

#first_volumeModels::RarVolume?

Get first volume

Returns:



37
38
39
# File 'lib/omnizip/formats/rar/volume_manager.rb', line 37

def first_volume
  @volumes.find(&:first?)
end

#last_volumeModels::RarVolume?

Get last volume

Returns:



44
45
46
# File 'lib/omnizip/formats/rar/volume_manager.rb', line 44

def last_volume
  @volumes.find(&:last?)
end

#multi_volume?Boolean

Check if this is a multi-volume archive

Returns:

  • (Boolean)

    true if multi-volume



30
31
32
# File 'lib/omnizip/formats/rar/volume_manager.rb', line 30

def multi_volume?
  @volumes.size > 1
end

#recovery_filesArray<String>

Get recovery files for volumes

Returns:

  • (Array<String>)

    Paths to .rev files



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/omnizip/formats/rar/volume_manager.rb', line 66

def recovery_files
  rev_files = []

  @volumes.each do |volume|
    # Check for .rev file for this volume
    rev_path = "#{volume.path}.rev"
    rev_files << rev_path if File.exist?(rev_path)
  end

  rev_files
end

#valid_sequence?Boolean

Validate volume sequence

Returns:

  • (Boolean)

    true if all volumes exist and sequence is valid



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/omnizip/formats/rar/volume_manager.rb', line 81

def valid_sequence?
  return true unless multi_volume?

  # Check all volumes exist
  return false unless @volumes.all?(&:exist?)

  # Check sequence is continuous
  expected_numbers = (0...@volumes.size).to_a
  actual_numbers = @volumes.map(&:volume_number).sort
  expected_numbers == actual_numbers
end

#volume_at(number) ⇒ Models::RarVolume?

Get volume by number

Parameters:

  • number (Integer)

    Volume number (0-based)

Returns:



52
53
54
# File 'lib/omnizip/formats/rar/volume_manager.rb', line 52

def volume_at(number)
  @volumes.find { |v| v.volume_number == number }
end

#volume_countInteger

Get total number of volumes

Returns:

  • (Integer)

    Number of volumes



23
24
25
# File 'lib/omnizip/formats/rar/volume_manager.rb', line 23

def volume_count
  @volumes.size
end

#volume_pathsArray<String>

Get all volume paths

Returns:

  • (Array<String>)

    Paths to all volumes



59
60
61
# File 'lib/omnizip/formats/rar/volume_manager.rb', line 59

def volume_paths
  @volumes.map(&:path)
end