Class: BinData::Transform::Lzma

Inherits:
IO::Transform show all
Defined in:
lib/bindata/transform/lzma.rb

Overview

Transforms a lzma compressed data stream.

gem install ruby-xz

Instance Method Summary collapse

Methods inherited from IO::Transform

#before_transform, #num_bytes_remaining, #offset, #prepend_to_chain, #seek_abs, #seekable?, #skip, transform_changes_stream_length!

Constructor Details

#initialize(read_length) ⇒ Lzma

Returns a new instance of Lzma.



11
12
13
14
# File 'lib/bindata/transform/lzma.rb', line 11

def initialize(read_length)
  super()
  @length = read_length
end

Instance Method Details

#after_read_transformObject

Raises:

  • (IOError)


26
27
28
# File 'lib/bindata/transform/lzma.rb', line 26

def after_read_transform
  raise IOError, "didn't read all data" unless @read.empty?
end

#after_write_transformObject



30
31
32
# File 'lib/bindata/transform/lzma.rb', line 30

def after_write_transform
  chain_write(::XZ::compress(@write))
end

#read(n) ⇒ Object



16
17
18
19
# File 'lib/bindata/transform/lzma.rb', line 16

def read(n)
  @read ||= ::XZ::decompress(chain_read(@length))
  @read.slice!(0...n)
end

#write(data) ⇒ Object



21
22
23
24
# File 'lib/bindata/transform/lzma.rb', line 21

def write(data)
  @write ||= create_empty_binary_string
  @write << data
end