Class: LZMA::Stream
- Inherits:
-
Object
- Object
- LZMA::Stream
- Defined in:
- lib/lzma.rb
Constant Summary collapse
- INIT =
[nil, 0, 0, nil, 0, 0, nil, nil, nil, nil, nil, nil, 0, 0, 0, 0, 0, 0].pack('PL!QPL!QPPPPPPQQL!L!i!i!').pointer.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #avail_in ⇒ Object
- #avail_out ⇒ Object
- #code(action) ⇒ Object
- #decoder(limit, flags) ⇒ Object
- #finalize ⇒ Object
-
#initialize(stream, buf_len = 4096) ⇒ Stream
constructor
A new instance of Stream.
- #next_in ⇒ Object
- #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.
85 86 87 88 89 90 91 |
# File 'lib/lzma.rb', line 85 def initialize(stream, buf_len=4096) @stream, @buf_len = stream, buf_len || 4096 @buf = (' ' * @buf_len).pointer @struct = C::LZMAStream.new(INIT) ObjectSpace.define_finalizer(self, method(:finalize)) end |
Class Method Details
.size ⇒ Object
161 162 163 |
# File 'lib/lzma.rb', line 161 def self.size C::LZMAStream.size end |
Instance Method Details
#avail_in ⇒ Object
97 98 99 |
# File 'lib/lzma.rb', line 97 def avail_in @struct[:avail_in] end |
#avail_out ⇒ Object
109 110 111 |
# File 'lib/lzma.rb', line 109 def avail_out @struct[:avail_out] end |
#code(action) ⇒ Object
147 148 149 150 151 |
# File 'lib/lzma.rb', line 147 def code(action) @struct[:next_out] = @buf @struct[:avail_out] = @buf_len C.lzma_code(@struct.pointer, action) end |
#decoder(limit, flags) ⇒ Object
137 138 139 140 |
# File 'lib/lzma.rb', line 137 def decoder(limit, flags) raise RuntimeError, "lzma_stream_decoder error" if C.lzma_auto_decoder(@struct.pointer, 0xffffffffffffffff, 0x02 | 0x08) != :OK self end |
#finalize ⇒ Object
157 158 159 |
# File 'lib/lzma.rb', line 157 def finalize C.lzma_end(@struct.pointer) end |
#next_in ⇒ Object
93 94 95 |
# File 'lib/lzma.rb', line 93 def next_in @struct[:next_in].read_string rescue nil end |
#next_out ⇒ Object
105 106 107 |
# File 'lib/lzma.rb', line 105 def next_out @struct[:next_out].read_string rescue nil end |
#ptr ⇒ Object
121 122 123 |
# File 'lib/lzma.rb', line 121 def ptr @struct.pointer end |
#read ⇒ Object
142 143 144 145 |
# File 'lib/lzma.rb', line 142 def read @struct[:next_in] = FFI::MemoryPointer.from_string(str = @stream.read(@buf_len)) @struct[:avail_in] = str.bytesize end |
#size ⇒ Object
125 126 127 |
# File 'lib/lzma.rb', line 125 def size @struct.size end |
#to_ffi ⇒ Object
117 118 119 |
# File 'lib/lzma.rb', line 117 def to_ffi @struct end |
#to_s ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/lzma.rb', line 129 def to_s %w[in out].flat_map {|i| %w[next avail total].map {|w| send("#{w}_#{i}".to_sym) } } end |
#total_in ⇒ Object
101 102 103 |
# File 'lib/lzma.rb', line 101 def total_in @struct[:total_in] end |
#total_out ⇒ Object
113 114 115 |
# File 'lib/lzma.rb', line 113 def total_out @struct[:total_out] end |