Method: LZMA::Decoder#read

Defined in:
lib/extlzma2/decoder.rb

#read(size = nil, buf = String.new) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/extlzma2/decoder.rb', line 13

def read(size = nil, buf = String.new)
  buf.clear
  size = size.to_i if size
  return buf if size == 0

  tmp = String.new
  while !eof && (size.nil? || size > 0)
    fetch or break if workbuf.eof?

    workbuf.read(size, tmp) or break
    buf << tmp
    size -= tmp.bytesize if size
  end

  buf
end