Class: Omnizip::Formats::Rar::Rar5::MultiVolume::VolumeManager
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::Rar5::MultiVolume::VolumeManager
- Defined in:
- lib/omnizip/formats/rar/rar5/multi_volume/volume_manager.rb
Overview
Volume manager for multi-volume archive creation
This class coordinates the creation of multi-volume RAR5 archives by managing volume splitting, file distribution, and volume writing.
Instance Attribute Summary collapse
-
#base_path ⇒ String
readonly
Base archive path.
-
#compression_options ⇒ Hash
readonly
Compression options.
-
#files ⇒ Array<Hash>
readonly
Files to archive.
-
#volume_options ⇒ VolumeOptions
readonly
Volume options.
Instance Method Summary collapse
-
#add_directory(dir_path, base_path = nil) ⇒ void
Add directory recursively.
-
#add_file(input_path, archive_path = nil) ⇒ void
Add file to archive.
-
#create_volumes ⇒ Array<String>
Create multi-volume archives.
-
#initialize(base_path, options = {}) ⇒ VolumeManager
constructor
Initialize volume manager.
-
#needs_splitting? ⇒ Boolean
Check if archive needs splitting.
Constructor Details
#initialize(base_path, options = {}) ⇒ VolumeManager
Initialize volume manager
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/omnizip/formats/rar/rar5/multi_volume/volume_manager.rb', line 44 def initialize(base_path, = {}) @base_path = base_path @volume_options = Models::VolumeOptions.new( max_volume_size: [:max_volume_size] || 104_857_600, volume_naming: [:volume_naming] || "part", ) @volume_options.validate! @compression_options = { compression: [:compression] || :store, level: [:level] || 3, include_mtime: [:include_mtime] || false, include_crc32: [:include_crc32] || false, } @files = [] end |
Instance Attribute Details
#base_path ⇒ String (readonly)
Returns Base archive path.
23 24 25 |
# File 'lib/omnizip/formats/rar/rar5/multi_volume/volume_manager.rb', line 23 def base_path @base_path end |
#compression_options ⇒ Hash (readonly)
Returns Compression options.
29 30 31 |
# File 'lib/omnizip/formats/rar/rar5/multi_volume/volume_manager.rb', line 29 def @compression_options end |
#files ⇒ Array<Hash> (readonly)
Returns Files to archive.
32 33 34 |
# File 'lib/omnizip/formats/rar/rar5/multi_volume/volume_manager.rb', line 32 def files @files end |
#volume_options ⇒ VolumeOptions (readonly)
Returns Volume options.
26 27 28 |
# File 'lib/omnizip/formats/rar/rar5/multi_volume/volume_manager.rb', line 26 def @volume_options end |
Instance Method Details
#add_directory(dir_path, base_path = nil) ⇒ void
This method returns an undefined value.
Add directory recursively
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/omnizip/formats/rar/rar5/multi_volume/volume_manager.rb', line 89 def add_directory(dir_path, base_path = nil) base_path ||= dir_path Dir.glob(File.join(dir_path, "**", "*")).each do |path| next unless File.file?(path) relative_path = path.sub( /^#{Regexp.escape(base_path)}#{File::SEPARATOR}?/, "" ) add_file(path, relative_path) end end |
#add_file(input_path, archive_path = nil) ⇒ void
This method returns an undefined value.
Add file to archive
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/omnizip/formats/rar/rar5/multi_volume/volume_manager.rb', line 67 def add_file(input_path, archive_path = nil) unless File.exist?(input_path) raise ArgumentError, "File not found: #{input_path}" end archive_path ||= File.basename(input_path) @files << { input: input_path, archive: archive_path, mtime: File.mtime(input_path), stat: File.stat(input_path), size: File.size(input_path), } end |
#create_volumes ⇒ Array<String>
Create multi-volume archives
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/omnizip/formats/rar/rar5/multi_volume/volume_manager.rb', line 105 def create_volumes # Prepare file entries with compression prepared_files = prepare_files # Calculate file distribution across volumes splitter = VolumeSplitter.new(max_volume_size: @volume_options.max_volume_size) distribution = splitter.calculate_file_distribution(prepared_files) # Create each volume volume_paths = [] distribution.each_with_index do |file_indices, volume_idx| volume_number = volume_idx + 1 is_last = (volume_idx == distribution.size - 1) volume_path = VolumeWriter.volume_filename( @base_path, volume_number, naming: @volume_options.volume_naming, ) write_volume(volume_path, volume_number, file_indices, prepared_files, is_last) volume_paths << volume_path end volume_paths end |
#needs_splitting? ⇒ Boolean
Check if archive needs splitting
136 137 138 139 140 |
# File 'lib/omnizip/formats/rar/rar5/multi_volume/volume_manager.rb', line 136 def needs_splitting? total_size = estimate_total_size VolumeSplitter.needs_splitting?(total_size, @volume_options.max_volume_size) end |