Class: Omnizip::Formats::Rar::Rar5::Solid::SolidManager
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::Rar5::Solid::SolidManager
- Defined in:
- lib/omnizip/formats/rar/rar5/solid/solid_manager.rb
Overview
Solid compression manager
This manager coordinates solid compression by:
- Collecting files into a SolidStream
- Compressing the entire stream with persistent dictionary
- Tracking file boundaries for extraction
The result is better compression ratios at the cost of:
- Cannot extract individual files without decompressing entire solid block
- Corruption in one file may affect others in the same block
Instance Attribute Summary collapse
-
#encoder ⇒ SolidEncoder
readonly
Compression encoder.
-
#level ⇒ Integer
readonly
Compression level.
-
#stream ⇒ SolidStream
readonly
File stream.
Instance Method Summary collapse
-
#add_file(filename, data, metadata = {}) ⇒ void
Add file to solid block.
-
#clear ⇒ void
Clear all data.
-
#compress_all ⇒ Hash
Compress all files in solid mode.
-
#compression_ratio(compressed_size) ⇒ Float
Calculate compression ratio.
-
#extract_file(compressed_data, file_index) ⇒ String?
Decompress solid stream and extract file.
-
#file_count ⇒ Integer
Get file count.
-
#has_files? ⇒ Boolean
Check if manager has files.
-
#initialize(options = {}) ⇒ SolidManager
constructor
Initialize solid manager.
-
#total_size ⇒ Integer
Get total uncompressed size.
Constructor Details
#initialize(options = {}) ⇒ SolidManager
Initialize solid manager
38 39 40 41 42 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 38 def initialize( = {}) @level = [:level] || 3 @stream = SolidStream.new @encoder = SolidEncoder.new(level: @level) end |
Instance Attribute Details
#encoder ⇒ SolidEncoder (readonly)
Returns Compression encoder.
29 30 31 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 29 def encoder @encoder end |
#level ⇒ Integer (readonly)
Returns Compression level.
32 33 34 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 32 def level @level end |
#stream ⇒ SolidStream (readonly)
Returns File stream.
26 27 28 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 26 def stream @stream end |
Instance Method Details
#add_file(filename, data, metadata = {}) ⇒ void
This method returns an undefined value.
Add file to solid block
50 51 52 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 50 def add_file(filename, data, = {}) @stream.add_file(filename, data, ) end |
#clear ⇒ void
This method returns an undefined value.
Clear all data
121 122 123 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 121 def clear @stream.clear end |
#compress_all ⇒ Hash
Compress all files in solid mode
Returns compressed data and file metadata needed for headers.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 63 def compress_all # Get concatenated data data = @stream.concatenated_data # Compress entire stream compressed = @encoder.compress_stream(data) { compressed_data: compressed, compressed_size: compressed.bytesize, uncompressed_size: data.bytesize, files: @stream.files.dup, } end |
#compression_ratio(compressed_size) ⇒ Float
Calculate compression ratio
129 130 131 132 133 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 129 def compression_ratio(compressed_size) return 0.0 if total_size.zero? compressed_size.to_f / total_size end |
#extract_file(compressed_data, file_index) ⇒ String?
Decompress solid stream and extract file
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 83 def extract_file(compressed_data, file_index) # Validate index return nil if file_index.negative? || file_index >= @stream.file_count # Decompress entire stream decompressed = @encoder.decompress_stream(compressed_data) # Extract specific file file = @stream.file_at(file_index) return nil unless file decompressed[file[:offset], file[:size]] end |
#file_count ⇒ Integer
Get file count
100 101 102 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 100 def file_count @stream.file_count end |
#has_files? ⇒ Boolean
Check if manager has files
114 115 116 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 114 def has_files? !@stream.empty? end |
#total_size ⇒ Integer
Get total uncompressed size
107 108 109 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_manager.rb', line 107 def total_size @stream.total_size end |