Class: LZMA::Encoder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, outport) ⇒ Encoder

Returns a new instance of Encoder.



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

def initialize(context, outport)
  super(context, outport, StringIO.new(String.new), String.new, [1])
  self.class.method(:finalizer_regist).call(self, context, outport, writebuf, workbuf, status)
end

Instance Attribute Details

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



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

def context
  @context
end

#outportObject

Returns the value of attribute outport

Returns:

  • (Object)

    the current value of outport



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

def outport
  @outport
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



6
7
8
# File 'lib/extlzma2/encoder.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/encoder.rb', line 6

def workbuf
  @workbuf
end

#writebufObject

Returns the value of attribute writebuf

Returns:

  • (Object)

    the current value of writebuf



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

def writebuf
  @writebuf
end

Instance Method Details

#closeObject



30
31
32
33
34
35
36
37
38
# File 'lib/extlzma2/encoder.rb', line 30

def close
  raise "already closed stream - #{inspect}" if eof?

  self.class.method(:finalizer_close).call(context, outport, workbuf)

  status[0] = nil

  nil
end

#eofObject Also known as: eof?



40
41
42
# File 'lib/extlzma2/encoder.rb', line 40

def eof
  !status[0]
end

#write(buf) ⇒ Object Also known as: <<



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

def write(buf)
  writebuf.rewind
  writebuf.string.clear
  writebuf << buf
  until writebuf.string.empty?
    s = context.code(writebuf.string, workbuf, self.class::BLOCKSIZE, 0)
    Utils.raise_err s unless s == 0
    outport << workbuf
    workbuf.clear
  end

  self
end