Class: Omnizip::Formats::SevenZip::SplitArchiveReader::MultiVolumeIO
- Inherits:
-
Object
- Object
- Omnizip::Formats::SevenZip::SplitArchiveReader::MultiVolumeIO
- Defined in:
- lib/omnizip/formats/seven_zip/split_archive_reader.rb
Overview
Multi-volume IO wrapper Provides unified IO interface across multiple volumes
Instance Method Summary collapse
-
#initialize(handles, paths) ⇒ MultiVolumeIO
constructor
A new instance of MultiVolumeIO.
-
#pos ⇒ Integer
Get current position.
-
#read(size) ⇒ String?
Read from current position.
-
#seek(pos, whence = ::IO::SEEK_SET) ⇒ Object
Seek to position across volumes.
-
#total_size ⇒ Integer
Get total size across all volumes.
Constructor Details
#initialize(handles, paths) ⇒ MultiVolumeIO
Returns a new instance of MultiVolumeIO.
514 515 516 517 518 519 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 514 def initialize(handles, paths) @handles = handles @paths = paths @position = 0 @combined_data = nil end |
Instance Method Details
#pos ⇒ Integer
Get current position
561 562 563 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 561 def pos @position end |
#read(size) ⇒ String?
Read from current position
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 540 def read(size) # Lazy-load combined data on first read if @combined_data.nil? load_combined_data end # Return nil if at EOF (matches IO behavior) return nil if @position >= @combined_data.bytesize available = @combined_data.bytesize - @position to_read = [size, available].min data = @combined_data[@position, to_read] @position += to_read data end |
#seek(pos, whence = ::IO::SEEK_SET) ⇒ Object
Seek to position across volumes
525 526 527 528 529 530 531 532 533 534 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 525 def seek(pos, whence = ::IO::SEEK_SET) case whence when ::IO::SEEK_SET @position = pos when ::IO::SEEK_CUR @position += pos when ::IO::SEEK_END @position = total_size + pos end end |
#total_size ⇒ Integer
Get total size across all volumes
568 569 570 |
# File 'lib/omnizip/formats/seven_zip/split_archive_reader.rb', line 568 def total_size @paths.sum { |path| File.size(path) } end |