Class: LZMA::Encoder

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, outport) ⇒ Encoder

Returns a new instance of Encoder.



154
155
156
157
158
159
# File 'lib/extlzma.rb', line 154

def initialize(context, outport)
  super(context, outport,
        StringIO.new("".force_encoding(Encoding::BINARY)),
        "".force_encoding(Encoding::BINARY), [1])
  self.class.method(:finalizer_regist).(self, context, outport, writebuf, workbuf, status)
end

Instance Attribute Details

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



151
152
153
# File 'lib/extlzma.rb', line 151

def context
  @context
end

#outportObject

Returns the value of attribute outport

Returns:

  • (Object)

    the current value of outport



151
152
153
# File 'lib/extlzma.rb', line 151

def outport
  @outport
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



151
152
153
# File 'lib/extlzma.rb', line 151

def status
  @status
end

#workbufObject

Returns the value of attribute workbuf

Returns:

  • (Object)

    the current value of workbuf



151
152
153
# File 'lib/extlzma.rb', line 151

def workbuf
  @workbuf
end

#writebufObject

Returns the value of attribute writebuf

Returns:

  • (Object)

    the current value of writebuf



151
152
153
# File 'lib/extlzma.rb', line 151

def writebuf
  @writebuf
end

Instance Method Details

#closeObject



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/extlzma.rb', line 179

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

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

  status[0] = nil

  nil
end

#eofObject Also known as: eof?



191
192
193
# File 'lib/extlzma.rb', line 191

def eof
  !status[0]
end

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



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/extlzma.rb', line 161

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

  self
end