Class: LZMA::Stream
- Inherits:
-
Object
- Object
- LZMA::Stream
- Defined in:
- lib/lzma.rb
Class Method Summary collapse
Instance Method Summary collapse
- #avail_in ⇒ Object
- #avail_out ⇒ Object
- #code(action) ⇒ Object
- #decoder(limit = -1,, flags = 0) ⇒ Object
- #finalize ⇒ Object
-
#initialize(stream, buf_len = 4096) ⇒ Stream
constructor
A new instance of Stream.
- #next_out ⇒ Object
- #ptr ⇒ Object
- #read ⇒ Object
- #size ⇒ Object
- #to_ffi ⇒ Object
- #to_s ⇒ Object
- #total_in ⇒ Object
- #total_out ⇒ Object
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
.size ⇒ Object
195 196 197 |
# File 'lib/lzma.rb', line 195 def self.size C::LZMAStream.size end |
Instance Method Details
#avail_in ⇒ Object
134 135 136 |
# File 'lib/lzma.rb', line 134 def avail_in @struct[:avail_in] end |
#avail_out ⇒ Object
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
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 |
#finalize ⇒ Object
191 192 193 |
# File 'lib/lzma.rb', line 191 def finalize C.lzma_end(@struct.pointer) end |
#next_out ⇒ Object
187 188 189 |
# File 'lib/lzma.rb', line 187 def next_out @buf.read_string_length(@buf_len - @struct[:avail_out]) end |
#ptr ⇒ Object
154 155 156 |
# File 'lib/lzma.rb', line 154 def ptr @struct.pointer end |
#read ⇒ Object
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 |
#size ⇒ Object
158 159 160 |
# File 'lib/lzma.rb', line 158 def size @struct.size end |
#to_ffi ⇒ Object
150 151 152 |
# File 'lib/lzma.rb', line 150 def to_ffi @struct end |
#to_s ⇒ Object
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_in ⇒ Object
138 139 140 |
# File 'lib/lzma.rb', line 138 def total_in @struct[:total_in] end |
#total_out ⇒ Object
146 147 148 |
# File 'lib/lzma.rb', line 146 def total_out @struct[:total_out] end |