Class: NMatrix::IO::Matlab::Mat5Reader::Compressed
- Includes:
- Packable
- Defined in:
- lib/nmatrix/io/mat5_reader.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#byte_order ⇒ Object
readonly
Returns the value of attribute byte_order.
Instance Method Summary collapse
- #compressed ⇒ Object
- #content ⇒ Object
-
#initialize(stream = nil, byte_order = nil, content_or_bytes = nil) ⇒ Compressed
constructor
A new instance of Compressed.
- #padded_bytes ⇒ Object
- #read_packed(packedio, options) ⇒ Object
- #write_packed(packedio, options = {}) ⇒ Object
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_order ⇒ Object (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
#compressed ⇒ Object
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 |
#content ⇒ Object
61 62 63 |
# File 'lib/nmatrix/io/mat5_reader.rb', line 61 def content @content ||= extract end |
#padded_bytes ⇒ Object
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, ) @compressed = (packedio >> [String, ]).first content end |
#write_packed(packedio, options = {}) ⇒ Object
70 71 72 |
# File 'lib/nmatrix/io/mat5_reader.rb', line 70 def write_packed(packedio, = {}) packedio << [compressed, {:bytes => padded_bytes}.merge()] end |