# ArrayBufferView.fromBytes() for JS target

**URL:** https://community.haxe.org/t/arraybufferview-frombytes-for-js-target/4653
**Category:** Haxe
**Tags:** haxe-js
**Created:** [August 11, 2025, 10:55pm UTC](https://community.haxe.org/t/arraybufferview-frombytes-for-js-target/4653 "2025-08-11T22:55:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![zagortenej](https://community.haxe.org/user_avatar/community.haxe.org/zagortenej/32/848_2.png) [@zagortenej](https://community.haxe.org/u/zagortenej)
#### Post date: [August 11, 2025, 10:55pm UTC](https://community.haxe.org/t/arraybufferview-frombytes-for-js-target/4653/1 "2025-08-11T22:55:41Z")

</div>

So, `haxe.io.ArrayBufferView.fromBytes()` does not exist for JS target as per docs (and source code, ofc): [haxe.io.ArrayBufferView - Haxe 4.3.7 API](https://api.haxe.org/haxe/io/ArrayBufferView.html)

Given how `fromBytes()` is implemented: [haxe/std/haxe/io/ArrayBufferView.hx at e0b355c6be312c1b17382603f018cf52522ec651 · HaxeFoundation/haxe · GitHub](https://github.com/HaxeFoundation/haxe/blob/e0b355c6be312c1b17382603f018cf52522ec651/std/haxe/io/ArrayBufferView.hx#L89) , could we have something similar for JS target?

`ArrayBufferViewData` for JS target is `js.lib.ArrayBufferView` which is a helper representing JS `TypedArray`. `Uint8Array` is one of the native JS typed arrays, and Haxe `UInt8ArrayData` can be used to implement `fromBytes` for JS in similar way it is in the source link above, i.e.:

```haxe
  public static function fromBytes(bytes:haxe.io.Bytes, pos = 0, ?length:Int):ArrayBufferView {
    if (length == null)
      length = bytes.length - pos;
    if (pos < 0 || length < 0 || pos + length > bytes.length)
      throw haxe.io.Error.OutsideBounds;
    return ArrayBufferView.fromData(haxe.io.UInt8Array.fromBytes(bytes, pos, length).getData());
  }

```

I’m aware that `UInt8ArrayData` for JS target does not unify with `ArrayBufferViewImpl` from the source link above, however the implementation in this post seems to work on JS target in my tests.

What would be the issue with this code to warrant not including it in `haxe/std/js/_std/haxe/io/ArrayBufferView.hx`? Or maybe it would be easier to answer: why don’t we have `fromBytes` for JS target?

---

<div class="post-metadata">

### Author: ![haxiomic](https://community.haxe.org/user_avatar/community.haxe.org/haxiomic/32/75_2.png) [@haxiomic](https://community.haxe.org/u/haxiomic)
#### Post date: [August 25, 2025, 12:26pm UTC](https://community.haxe.org/t/arraybufferview-frombytes-for-js-target/4653/2 "2025-08-25T12:26:55Z")

</div>

Checkout the typedarray implementation here, this is designed to better align with JS

I think the answer is down to time available to implement in the stdlib, I imagine a PR would be welcome

> **[gluon/typedarray at master · haxiomic/gluon](https://github.com/haxiomic/gluon/tree/master/typedarray)**
>
> WebGL implementation for hxcpp. Contribute to haxiomic/gluon development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![zagortenej](https://community.haxe.org/user_avatar/community.haxe.org/zagortenej/32/848_2.png) [@zagortenej](https://community.haxe.org/u/zagortenej)
#### Post date: [September 6, 2025, 9:05pm UTC](https://community.haxe.org/t/arraybufferview-frombytes-for-js-target/4653/3 "2025-09-06T21:05:24Z")

</div>

Here goes nothin’ 🙂 [[js] implement haxe.io.ArrayBufferView.fromBytes() by zagortenej · Pull Request #12358 · HaxeFoundation/haxe · GitHub](https://github.com/HaxeFoundation/haxe/pull/12358)
