Class: Omnizip::Formats::SevenZip::SplitArchiveReader::MultiVolumeIO

Inherits:
Object
  • Object
show all
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

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

#posInteger

Get current position

Returns:

  • (Integer)

    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

Parameters:

  • size (Integer)

    Number of bytes to read

Returns:

  • (String, nil)

    Read data, or nil if at EOF



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

Parameters:

  • pos (Integer)

    Position to seek to

  • whence (Integer) (defaults to: ::IO::SEEK_SET)

    Seek mode



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_sizeInteger

Get total size across all volumes

Returns:

  • (Integer)

    Total size



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