Created
January 24, 2017 00:53
-
-
Save thomasuster/d6b52406490f452982ba58eac1a84f46 to your computer and use it in GitHub Desktop.
Convert a haxe.io.BytesBuffer to js.html.ArrayBuffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.thomasuster.js; | |
import js.html.Blob; | |
import haxe.io.Bytes; | |
import haxe.io.BytesBuffer; | |
import js.html.ArrayBuffer; | |
import js.html.DataView; | |
class ByteBufferConverter { | |
public function new():Void {} | |
public function toArrayBuffer(bb:BytesBuffer):ArrayBuffer { | |
var bytes:Bytes = bb.getBytes(); | |
var buffer:ArrayBuffer = new ArrayBuffer(bytes.length); | |
var view:DataView = new DataView(buffer, 0, buffer.byteLength); | |
for (i in 0...bytes.length) { | |
view.setUint8(i, bytes.get(i)); | |
} | |
return buffer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment