Class: Zip::Bzip2::Libbz2

Inherits:
Object
  • Object
show all
Defined in:
lib/zip/bzip2/libbz2.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLibbz2

Returns a new instance of Libbz2.



27
28
29
# File 'lib/zip/bzip2/libbz2.rb', line 27

def initialize
  @stream = FFI::Libbz2::BzStream.new
end

Class Method Details

.buffer(length) ⇒ Object



17
18
19
# File 'lib/zip/bzip2/libbz2.rb', line 17

def self.buffer(length)
  ::FFI::MemoryPointer.new(1, length)
end

.buffer_from_data(data) ⇒ Object



21
22
23
24
25
# File 'lib/zip/bzip2/libbz2.rb', line 21

def self.buffer_from_data(data)
  buffer = ::FFI::MemoryPointer.new(1, data.bytesize)
  buffer.write_bytes(data)
  buffer
end

Instance Method Details

#decompress!Object



40
41
42
43
44
45
# File 'lib/zip/bzip2/libbz2.rb', line 40

def decompress!
  result = FFI::Libbz2::BZ2_bzDecompress(@stream)
  check_error(result)

  result == FFI::Libbz2::BZ_STREAM_END
end

#decompress_end!Object



47
48
49
50
51
52
53
54
# File 'lib/zip/bzip2/libbz2.rb', line 47

def decompress_end!
  result = FFI::Libbz2::BZ2_bzDecompressEnd(@stream)
  check_error(result)

  ObjectSpace.undefine_finalizer(self)

  true
end

#decompress_init!(small = false) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/zip/bzip2/libbz2.rb', line 31

def decompress_init!(small = false)
  result = FFI::Libbz2::BZ2_bzDecompressInit(@stream, 0, small ? 1 : 0)
  check_error(result)

  ObjectSpace.define_finalizer(self, self.class.send(:finalizer, @stream))

  true
end

#input?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/zip/bzip2/libbz2.rb', line 67

def input?
  @stream[:avail_in].positive?
end

#input_buffer=(input_buffer) ⇒ Object



56
57
58
59
# File 'lib/zip/bzip2/libbz2.rb', line 56

def input_buffer=(input_buffer)
  @stream[:next_in] = input_buffer
  @stream[:avail_in] = input_buffer.size
end

#outputObject



71
72
73
# File 'lib/zip/bzip2/libbz2.rb', line 71

def output
  @output_buffer.read_bytes(@output_buffer.size - @stream[:avail_out])
end

#output_buffer=(output_buffer) ⇒ Object



61
62
63
64
65
# File 'lib/zip/bzip2/libbz2.rb', line 61

def output_buffer=(output_buffer)
  @output_buffer = output_buffer
  @stream[:next_out] = output_buffer
  @stream[:avail_out] = output_buffer.size
end