Uint8Array is a specialised type of array that only contains bytes (Uint8). It is a faster and more memory efficient version of `BinData::Array.new(:type => :uint8)`.
require 'bindata' obj = BinData::Uint8Array.new(initial_length: 5) obj.read("abcdefg") #=> [97, 98, 99, 100, 101] obj[2] #=> 99 obj.collect { |x| x.chr }.join #=> "abcde"
Parameters may be provided at initialisation to control the behaviour of an object. These params are:
:initial_length
The initial length of the array.
:read_until
May only have a value of `:eof`. This parameter instructs the array to read as much data from the stream as possible.
# File lib/bindata/uint8_array.rb, line 36 def read_and_return_value(io) if has_parameter?(:initial_length) data = io.readbytes(eval_parameter(:initial_length)) else data = io.read_all_bytes end data.unpack("C*") end
# File lib/bindata/uint8_array.rb, line 46 def sensible_default [] end
# File lib/bindata/uint8_array.rb, line 32 def value_to_binary_string(val) val.pack("C*") end