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.
84 85 86 87 88 89 90 |
# File 'lib/lzma.rb', line 84 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
153 154 155 |
# File 'lib/lzma.rb', line 153 def self.size C::LZMAStream.size end |
Instance Method Details
#avail_in ⇒ Object
92 93 94 |
# File 'lib/lzma.rb', line 92 def avail_in @struct[:avail_in] end |
#avail_out ⇒ Object
100 101 102 |
# File 'lib/lzma.rb', line 100 def avail_out @struct[:avail_out] end |
#code(action) ⇒ Object
139 140 141 142 143 |
# File 'lib/lzma.rb', line 139 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
128 129 130 131 132 |
# File 'lib/lzma.rb', line 128 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
149 150 151 |
# File 'lib/lzma.rb', line 149 def finalize C.lzma_end(@struct.pointer) end |
#next_out ⇒ Object
145 146 147 |
# File 'lib/lzma.rb', line 145 def next_out @buf.read_string_length(@buf_len - @struct[:avail_out]) end |
#ptr ⇒ Object
112 113 114 |
# File 'lib/lzma.rb', line 112 def ptr @struct.pointer end |
#read ⇒ Object
134 135 136 137 |
# File 'lib/lzma.rb', line 134 def read @struct[:next_in] = FFI::MemoryPointer.from_string(str = @stream.read(@buf_len)) @struct[:avail_in] = str.bytesize end |
#size ⇒ Object
116 117 118 |
# File 'lib/lzma.rb', line 116 def size @struct.size end |
#to_ffi ⇒ Object
108 109 110 |
# File 'lib/lzma.rb', line 108 def to_ffi @struct end |
#to_s ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/lzma.rb', line 120 def to_s %w[in out].flat_map {|i| %w[next avail total].map {|w| send("#{w}_#{i}".to_sym) } } end |
#total_in ⇒ Object
96 97 98 |
# File 'lib/lzma.rb', line 96 def total_in @struct[:total_in] end |
#total_out ⇒ Object
104 105 106 |
# File 'lib/lzma.rb', line 104 def total_out @struct[:total_out] end |