Class: LZMA::Stream

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream, buf_len = 4096) ⇒ Stream

Returns a new instance of Stream.



126
127
128
129
130
131
132
# File 'lib/lzma.rb', line 126

def initialize(stream, buf_len=4096)
  @stream, @buf_len = stream, buf_len || 4096
  @buf = (' ' * @buf_len).pointer
  @struct = C::LZMAStream.new

  ObjectSpace.define_finalizer(self, method(:finalize))
end

Class Method Details

.sizeObject



195
196
197
# File 'lib/lzma.rb', line 195

def self.size
  C::LZMAStream.size
end

Instance Method Details

#avail_inObject



134
135
136
# File 'lib/lzma.rb', line 134

def avail_in
  @struct[:avail_in]
end

#avail_outObject



142
143
144
# File 'lib/lzma.rb', line 142

def avail_out
  @struct[:avail_out]
end

#code(action) ⇒ Object



181
182
183
184
185
# File 'lib/lzma.rb', line 181

def code(action)
  @struct[:next_out] = @buf
  @struct[:avail_out] = @buf_len
  C.lzma_code(@struct.pointer, action)
end

#decoder(limit = -1,, flags = 0) ⇒ Object

Raises:

  • (RuntimeError)


170
171
172
173
174
# File 'lib/lzma.rb', line 170

def decoder(limit=-1, flags=0)
  code = nil
  raise RuntimeError, "lzma_stream_decoder error: #{code}" if (code = C.lzma_auto_decoder(@struct.pointer, limit, flags)) != :OK
  self
end

#finalizeObject



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

def finalize
  C.lzma_end(@struct.pointer)
end

#next_outObject



187
188
189
# File 'lib/lzma.rb', line 187

def next_out
  @buf.read_string_length(@buf_len - @struct[:avail_out])
end

#ptrObject



154
155
156
# File 'lib/lzma.rb', line 154

def ptr
  @struct.pointer
end

#readObject



176
177
178
179
# File 'lib/lzma.rb', line 176

def read
  @struct[:next_in] = FFI::MemoryPointer.from_string(str = @stream.read(@buf_len))
  @struct[:avail_in] = str.bytesize
end

#sizeObject



158
159
160
# File 'lib/lzma.rb', line 158

def size
  @struct.size
end

#to_ffiObject



150
151
152
# File 'lib/lzma.rb', line 150

def to_ffi
  @struct
end

#to_sObject



162
163
164
165
166
167
168
# File 'lib/lzma.rb', line 162

def to_s
  %w[in out].flat_map {|i|
    %w[next avail total].map {|w|
      send("#{w}_#{i}".to_sym)
    }
  }
end

#total_inObject



138
139
140
# File 'lib/lzma.rb', line 138

def total_in
  @struct[:total_in]
end

#total_outObject



146
147
148
# File 'lib/lzma.rb', line 146

def total_out
  @struct[:total_out]
end