Class: LZMA::Decoder

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

Constant Summary collapse

BLOCKSIZE =

256 KiB

256 * 1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, inport) ⇒ Decoder

Returns a new instance of Decoder.



237
238
239
240
241
242
# File 'lib/extlzma.rb', line 237

def initialize(context, inport)
  super context, inport,
        "".force_encoding(Encoding::BINARY),
        StringIO.new("".force_encoding(Encoding::BINARY)),
        :ready
end

Instance Attribute Details

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



234
235
236
# File 'lib/extlzma.rb', line 234

def context
  @context
end

#inportObject

Returns the value of attribute inport

Returns:

  • (Object)

    the current value of inport



234
235
236
# File 'lib/extlzma.rb', line 234

def inport
  @inport
end

#readbufObject

Returns the value of attribute readbuf

Returns:

  • (Object)

    the current value of readbuf



234
235
236
# File 'lib/extlzma.rb', line 234

def readbuf
  @readbuf
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



234
235
236
# File 'lib/extlzma.rb', line 234

def status
  @status
end

#workbufObject

Returns the value of attribute workbuf

Returns:

  • (Object)

    the current value of workbuf



234
235
236
# File 'lib/extlzma.rb', line 234

def workbuf
  @workbuf
end

Instance Method Details

#closeObject



269
270
271
272
273
274
# File 'lib/extlzma.rb', line 269

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

#eofObject Also known as: eof?



263
264
265
# File 'lib/extlzma.rb', line 263

def eof
  !status && workbuf.eof?
end

#read(size = nil, buf = "".force_encoding(Encoding::BINARY)) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/extlzma.rb', line 244

def read(size = nil, buf = "".force_encoding(Encoding::BINARY))
  buf.clear
  size = size.to_i if size
  return buf if size == 0

  tmp = "".force_encoding(Encoding::BINARY)
  while !eof && (size.nil? || size > 0)
    if workbuf.eof?
      fetch or break
    end

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

  (buf.empty? ? nil : buf)
end