Skip to content

Conversation

@Geokureli
Copy link
Contributor

@Geokureli Geokureli commented Jan 25, 2026

Potentially related to: openfl/openfl#2360

In JS the underlying byte data may have extras, due to the underlying types used in js, explained here: HaxeFoundation/haxe#8974. This pr will ignore those extras.

Example reproducing the inconsistent behavior:

final output = new haxe.io.BytesOutput();
output.writeString("test");
final byteArray = lime.utils.Bytes.fromBytes(output.getBytes());
trace('byteArray.length: ${byteArray.length}'); // 16 on JS, 4 otherwise

Tested on chrome for mac

@player-03
Copy link
Contributor

Tested on chrome for mac

I also got 16 in Firefox on Linux.

@Geokureli
Copy link
Contributor Author

I also added a fix to haxe, but lime should probably account for this on older versions

#if js
this = new HaxeBytes(bytesData);
// bytesData may have extra bytes. See https://github.com/HaxeFoundation/haxe/issues/8974
this = new HaxeBytes(bytesData.slice(0, length));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slice copies the buffer, so perhaps another option might be to just manually override: this.length = length? (might require @:privateAccess)

Copy link
Contributor Author

@Geokureli Geokureli Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't require @:privateAccess as the abstract has @:access(haxe.io.Bytes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants