Sha256: d3fc26e9bc6e7a73ebaf49b38f8d81a650bfba2783dc2ef912e57ce80f3a1d2f

Contents?: true

Size: 683 Bytes

Versions: 11

Compression:

Stored size: 683 Bytes

Contents

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

11 entries across 11 versions & 2 rubygems

Version Path
opal-0.7.0.beta3 stdlib/buffer.rb
opal-0.6.3 stdlib/buffer.rb
opal-0.7.0.beta2 stdlib/buffer.rb
opal-cj-0.7.0.beta2 stdlib/buffer.rb
opal-cj-0.7.0.beta1 stdlib/buffer.rb
opal-0.7.0.beta1 stdlib/buffer.rb
opal-0.6.2 stdlib/buffer.rb
opal-0.6.1 stdlib/buffer.rb
opal-0.6.0 stdlib/buffer.rb
opal-0.5.5 stdlib/buffer.rb
opal-0.5.4 stdlib/buffer.rb