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.10.0.beta4 stdlib/buffer.rb
opal-0.10.0.beta3 stdlib/buffer.rb
opal-0.10.0.beta2 stdlib/buffer.rb
opal-0.10.0.beta1 stdlib/buffer.rb
opal-0.9.2 stdlib/buffer.rb
opal-0.9.0 stdlib/buffer.rb
opal-0.9.0.rc1 stdlib/buffer.rb
opal-0.9.0.beta2 stdlib/buffer.rb
opal-0.9.0.beta1 stdlib/buffer.rb
opal-0.8.1 stdlib/buffer.rb
opal-0.8.1.rc1 stdlib/buffer.rb
opal-wedge-0.9.0.dev stdlib/buffer.rb
opal-0.8.0 stdlib/buffer.rb
opal-0.8.0.rc3 stdlib/buffer.rb
opal-0.8.0.rc2 stdlib/buffer.rb
opal-0.8.0.rc1 stdlib/buffer.rb
opal-0.8.0.beta1 stdlib/buffer.rb
opal-0.7.2 stdlib/buffer.rb
opal-0.7.1 stdlib/buffer.rb
opal-0.7.0 stdlib/buffer.rb