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.



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

.sizeObject



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

def self.size
  C::LZMAStream.size
end

Instance Method Details

#avail_inObject



92
93
94
# File 'lib/lzma.rb', line 92

def avail_in
  @struct[:avail_in]
end

#avail_outObject



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

Raises:

  • (RuntimeError)


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

#finalizeObject



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

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

#next_outObject



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

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

#ptrObject



112
113
114
# File 'lib/lzma.rb', line 112

def ptr
  @struct.pointer
end

#readObject



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

#sizeObject



116
117
118
# File 'lib/lzma.rb', line 116

def size
  @struct.size
end

#to_ffiObject



108
109
110
# File 'lib/lzma.rb', line 108

def to_ffi
  @struct
end

#to_sObject



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_inObject



96
97
98
# File 'lib/lzma.rb', line 96

def total_in
  @struct[:total_in]
end

#total_outObject



104
105
106
# File 'lib/lzma.rb', line 104

def total_out
  @struct[:total_out]
end