Class: Omnizip::Formats::SevenZip::SplitArchiveReader
- Inherits:
-
Object
- Object
- Omnizip::Formats::SevenZip::SplitArchiveReader
- Includes:
- Constants
- Defined in:
- lib/omnizip/formats/seven_zip/split_archive_reader.rb
Overview
Split archive reader for .7z format Reads multi-volume archives
Defined Under Namespace
Classes: MultiVolumeIO
Constant Summary
Constants included from Constants
Constants::MAJOR_VERSION, Constants::MAX_NUM_BONDS, Constants::MAX_NUM_CODERS, Constants::MAX_NUM_PACK_STREAMS, Constants::MINOR_VERSION, Constants::SIGNATURE, Constants::SIGNATURE_SIZE, Constants::START_HEADER_SIZE
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#stream_info ⇒ Object
readonly
Returns the value of attribute stream_info.
-
#volumes ⇒ Object
readonly
Returns the value of attribute volumes.
Instance Method Summary collapse
-
#close ⇒ Object
Close all volume handles.
-
#extract_all(output_dir) ⇒ Object
Extract all files to directory.
-
#extract_entry(entry_name, output_path) ⇒ Object
Extract file to output path.
-
#initialize(base_path) ⇒ SplitArchiveReader
constructor
Initialize reader with base path.
-
#list_files ⇒ Array<Models::FileEntry>
List all files in archive.
-
#open ⇒ Object
Detect and open all volumes.
-
#split? ⇒ Boolean
Check if archive is split.
-
#total_volumes ⇒ Integer
Get total number of volumes.
-
#valid? ⇒ Boolean
Check if archive is valid .7z format.
-
#volume_size ⇒ Integer
Get volume size (first volume).
Constructor Details
#initialize(base_path) ⇒ SplitArchiveReader
Initialize reader with base path
18 19 20 21 22 23 24 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 18 def initialize(base_path) @base_path = base_path @entries = [] @stream_info = nil @volumes = [] @volume_handles = [] end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
13 14 15 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 13 def base_path @base_path end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
13 14 15 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 13 def entries @entries end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
13 14 15 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 13 def header @header end |
#stream_info ⇒ Object (readonly)
Returns the value of attribute stream_info.
13 14 15 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 13 def stream_info @stream_info end |
#volumes ⇒ Object (readonly)
Returns the value of attribute volumes.
13 14 15 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 13 def volumes @volumes end |
Instance Method Details
#close ⇒ Object
Close all volume handles
118 119 120 121 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 118 def close @volume_handles.each(&:close) @volume_handles.clear end |
#extract_all(output_dir) ⇒ Object
Extract all files to directory
101 102 103 104 105 106 107 108 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 101 def extract_all(output_dir) FileUtils.mkdir_p(output_dir) @entries.each do |entry| output_path = File.join(output_dir, entry.name) extract_entry(entry.name, output_path) end end |
#extract_entry(entry_name, output_path) ⇒ Object
Extract file to output path
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 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 71 def extract_entry(entry_name, output_path) entry = @entries.find { |e| e.name == entry_name } raise "Entry not found: #{entry_name}" unless entry # Create directory if needed FileUtils.mkdir_p(File.dirname(output_path)) # Extract file if entry.directory? FileUtils.mkdir_p(output_path) elsif entry.has_stream? data = extract_entry_data(entry) File.binwrite(output_path, data) # Set timestamp if available if entry.mtime File.utime(entry.atime || entry.mtime || Time.now, entry.mtime || Time.now, output_path) end else # Empty file FileUtils.touch(output_path) end end |
#list_files ⇒ Array<Models::FileEntry>
List all files in archive
62 63 64 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 62 def list_files @entries end |
#open ⇒ Object
Detect and open all volumes
29 30 31 32 33 34 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 29 def open detect_volumes open_volumes parse_archive self end |
#split? ⇒ Boolean
Check if archive is split
39 40 41 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 39 def split? @volumes.size > 1 end |
#total_volumes ⇒ Integer
Get total number of volumes
46 47 48 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 46 def total_volumes @volumes.size end |
#valid? ⇒ Boolean
Check if archive is valid .7z format
113 114 115 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 113 def valid? !@header.nil? && @header.valid? end |
#volume_size ⇒ Integer
Get volume size (first volume)
53 54 55 56 57 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 53 def volume_size return 0 if @volumes.empty? File.size(@volumes.first) end |