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.



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

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

Class Method Details

.buffer(length) ⇒ Object



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

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

.buffer_from_data(data) ⇒ Object



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

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

Instance Method Details

#decompress!Object



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

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

  result == FFI::Libbz2::BZ_STREAM_END
end

#decompress_end!Object



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

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

  ObjectSpace.undefine_finalizer(self)

  true
end

#decompress_init!(small: false) ⇒ Object



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

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)


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

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

#input_buffer=(input_buffer) ⇒ Object



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

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

#outputObject



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

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

#output_buffer=(output_buffer) ⇒ Object



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

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