Sha256: ecb9dbedaff25271bdb9291c3eeebe9ee2ff7fc974c357318587987affbe78fa

Contents?: true

Size: 700 Bytes

Versions: 41

Compression:

Stored size: 700 Bytes

Contents

require 'native'
require 'buffer/array'
require 'buffer/view'

class Buffer
  include Native

  def self.supported?
    not $$[:ArrayBuffer].nil?
  end

  def self.name_for(bits, type)
    "#{case type
      when :unsigned then 'Uint'
      when :signed   then 'Int'
      when :float    then 'Float'
    end}#{bits}"
  end

  def initialize(size, bits = 8)
    if native?(size)
      super(size)
    else
      super(`new ArrayBuffer(size * (bits / 8))`)
    end
  end

  def length
    `#@native.byteLength`
  end

  alias size length

  def to_a(bits = 8, type = :unsigned)
    Array.new(self, bits, type)
  end

  def view(offset = nil, length = nil)
    View.new(self, offset, length)
  end
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
opal-0.11.4 stdlib/buffer.rb
opal-0.11.3 stdlib/buffer.rb
opal-0.11.2 stdlib/buffer.rb
opal-0.11.1 stdlib/buffer.rb
opal-0.11.1.pre stdlib/buffer.rb
opal-0.10.6 stdlib/buffer.rb
opal-0.10.6.beta stdlib/buffer.rb
opal-0.11.0 stdlib/buffer.rb
opal-0.10.5 stdlib/buffer.rb
opal-0.10.4 stdlib/buffer.rb
opal-0.11.0.rc1 stdlib/buffer.rb
opal-0.10.3 stdlib/buffer.rb
opal-0.10.2 stdlib/buffer.rb
opal-0.10.1 stdlib/buffer.rb
opal-0.10.0 stdlib/buffer.rb
opal-0.10.0.rc2 stdlib/buffer.rb
opal-0.9.4 stdlib/buffer.rb
opal-0.9.3 stdlib/buffer.rb
opal-0.10.0.rc1 stdlib/buffer.rb
opal-0.10.0.beta5 stdlib/buffer.rb