Class: LZMA::Decoder

Inherits:
Struct
  • Object
show all
Defined in:
lib/extlzma2/decoder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, inport) ⇒ Decoder

Returns a new instance of Decoder.



9
10
11
# File 'lib/extlzma2/decoder.rb', line 9

def initialize(context, inport)
  super(context, inport, String.new, StringIO.new(String.new), :ready)
end

Instance Attribute Details

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



6
7
8
# File 'lib/extlzma2/decoder.rb', line 6

def context
  @context
end

#inportObject

Returns the value of attribute inport

Returns:

  • (Object)

    the current value of inport



6
7
8
# File 'lib/extlzma2/decoder.rb', line 6

def inport
  @inport
end

#readbufObject

Returns the value of attribute readbuf

Returns:

  • (Object)

    the current value of readbuf



6
7
8
# File 'lib/extlzma2/decoder.rb', line 6

def readbuf
  @readbuf
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



6
7
8
# File 'lib/extlzma2/decoder.rb', line 6

def status
  @status
end

#workbufObject

Returns the value of attribute workbuf

Returns:

  • (Object)

    the current value of workbuf



6
7
8
# File 'lib/extlzma2/decoder.rb', line 6

def workbuf
  @workbuf
end

Instance Method Details

#closeObject



36
37
38
39
40
41
# File 'lib/extlzma2/decoder.rb', line 36

def close
  self.status = nil
  workbuf.rewind
  workbuf.string.clear
  nil
end

#eofObject Also known as: eof?



30
31
32
# File 'lib/extlzma2/decoder.rb', line 30

def eof
  !status && workbuf.eof?
end

#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