Method: IOExtras::AbstractInputStream#read

Defined in:
lib/zip/ioextras.rb

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/zip/ioextras.rb', line 45

def read(numberOfBytes = nil, buf = nil)
  tbuf = nil

  if @outputBuffer.length > 0
    if numberOfBytes <= @outputBuffer.length
      tbuf = @outputBuffer.slice!(0, numberOfBytes)
    else
      numberOfBytes -= @outputBuffer.length if (numberOfBytes)
      rbuf = sysread(numberOfBytes, buf)
      tbuf = @outputBuffer
      tbuf << rbuf if (rbuf)
      @outputBuffer = ""
    end
  else
    tbuf = sysread(numberOfBytes, buf)
  end

  return nil unless (tbuf)

  if buf
    buf.replace(tbuf)
  else
    buf = tbuf
  end

  buf
end