Class: PEdump::CompositeIO

Inherits:
Object show all
Defined in:
lib/pedump/composite_io.rb

Instance Method Summary collapse

Constructor Details

#initialize(*ios) ⇒ CompositeIO

Returns a new instance of CompositeIO.



3
4
5
6
# File 'lib/pedump/composite_io.rb', line 3

def initialize(*ios)
  @ios = ios.flatten
  @pos = 0
end

Instance Method Details

#eof?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/pedump/composite_io.rb', line 29

def eof?
  @ios.all?(&:eof?)
end

#read(amount = nil, buf = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pedump/composite_io.rb', line 8

def read(amount = nil, buf = nil)
  buf ||= ''; buf1 = ''

  # truncates buffer to zero length if nothing read
  @ios.first.read(amount,buf)

  @ios[1..-1].each do |io|
    break if amount && buf.size >= amount
    io.read(amount ? (amount-buf.size) : nil, buf1)
    buf << buf1
  end

  @pos += buf.size

  buf.size > 0 ? buf : (amount ? nil : buf )
end

#tellObject



25
26
27
# File 'lib/pedump/composite_io.rb', line 25

def tell
  @pos
end