Sha256: 075148e525b8f02358f94c738dbc5a9804545c36eda213848252a328bb7b1c3b
Contents?: true
Size: 818 Bytes
Versions: 6
Compression:
Stored size: 818 Bytes
Contents
# backtick_javascript: true require 'native' require 'buffer/array' require 'buffer/view' class Buffer include Native::Wrapper def self.supported? !$$[:ArrayBuffer].nil? end def self.name_for(bits, type) part = case type when :unsigned then 'Uint' when :signed then 'Int' when :float then 'Float' end "#{part}#{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 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 def to_s to_a.to_a.pack('c*') end alias size length end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
opal-1.8.3.rc1 | stdlib/buffer.rb |
opal-1.8.2 | stdlib/buffer.rb |
opal-1.8.1 | stdlib/buffer.rb |
opal-1.8.0 | stdlib/buffer.rb |
opal-1.8.0.beta1 | stdlib/buffer.rb |
opal-1.8.0.alpha1 | stdlib/buffer.rb |