HaxeFoundation / HaxeFoundation/hxnodejs

Current implementation of hxFromBytes incompatible with Node 4.x

Open
#98 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
177
Forks
58
PR merge metrics
No merged PRs in 30d

Description

Before `hxFromBytes(foo)` would generate

```js
new Buffer(foo.b.bufferValue)
```

but that changed with HaxeFoundation/hxnodejs@19a1e2b9af60860b0f0b9e0d5f2a933ff12c6031 (and HaxeFoundation/hxnodejs@9b24a891e640beca1bb57dea31800acafe696ebb) to

```js
new Buffer(foo.b.bytes, foo.b.byteOffset, foo.b.byteLength)
```

However, the history of the `new Buffer(arrayBuffer, offset, length)` NodeJS constructor [isn't as linear as one would hope](https://nodejs.org/dist/latest-v8.x/docs/api/buffer.html#buffer_new_buffer_arraybuffer_byteoffset_length):

![NodeJS new Buffer](https://files.slack.com/files-pri/T1K0XPFSM-F790HLQN4/screenshot_from_2017-09-27_11-13-36.png?pub_secret=3a82ddc811)

Since the constructor isn't supported in Node 4.x, the current implementation has the effect of calling `new Buffer(foo.b.bytes)`, making the new buffer point to the _entire_ underlying array buffer of `foo`, that _will also contain data for other buffers_, because of pooling.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.