Class: NMatrix::IO::Matlab::Mat5Reader::Compressed

Inherits:
Object
  • Object
show all
Includes:
Packable
Defined in:
lib/nmatrix/io/mat5_reader.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream = nil, byte_order = nil, content_or_bytes = nil) ⇒ Compressed

Returns a new instance of Compressed.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/nmatrix/io/mat5_reader.rb', line 43

def initialize(stream = nil, byte_order = nil, content_or_bytes = nil)
  @stream   = stream
  @byte_order = byte_order

  if content_or_bytes.is_a?(String)
    @content = content_or_bytes

  elsif content_or_bytes.is_a?(Fixnum)
    @padded_bytes = content_or_bytes
  end
end

Instance Attribute Details

#byte_orderObject (readonly)

Returns the value of attribute byte_order.



41
42
43
# File 'lib/nmatrix/io/mat5_reader.rb', line 41

def byte_order
  @byte_order
end

Instance Method Details

#compressedObject



55
56
57
58
59
# File 'lib/nmatrix/io/mat5_reader.rb', line 55

def compressed
  require "zlib"
  # [2..-5] removes headers
  @compressed ||= Zlib::Deflate.deflate(content)
end

#contentObject



61
62
63
# File 'lib/nmatrix/io/mat5_reader.rb', line 61

def content
  @content ||= extract
end

#padded_bytesObject



65
66
67
68
# File 'lib/nmatrix/io/mat5_reader.rb', line 65

def padded_bytes
  @padded_bytes ||= content.size % 4 == 0 ? \
   content.size : (content.size / 4 + 1) * 4
end

#read_packed(packedio, options) ⇒ Object



74
75
76
77
# File 'lib/nmatrix/io/mat5_reader.rb', line 74

def read_packed(packedio, options)
  @compressed = (packedio >> [String, options]).first
  content
end

#write_packed(packedio, options = {}) ⇒ Object



70
71
72
# File 'lib/nmatrix/io/mat5_reader.rb', line 70

def write_packed(packedio, options = {})
  packedio << [compressed, {:bytes => padded_bytes}.merge(options)]
end