Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for ArrayBuffer and the various TypedArrays #69

Merged
merged 4 commits into from
Sep 25, 2024

Conversation

LorisSigrist
Copy link
Contributor

This is something that tripped me up a couple times, and given that #26 is three years old, I'm likely not the only one.

This PR adds support for ArrayBuffer and the various Typed Arrays (Uint8Array etc). It serialises them by encoding the underlying ArrayBuffer in base64.

I chose not to do the pointer-value style encoding that arrays use for the following reasons:

  • ArrayBuffers are never hole-y, so the potential savings are lesser
  • ArrayBuffers often represent images and likely have highly varied values. Pointer-value would likely be longer.

Since atob and btoa are not included in the project's ts libs I used JS implementations of both. I didn't want to introduce additional libs without consulting first.

@nounder
Copy link

nounder commented Aug 5, 2024

As an alternative, check out typeson. It supports different types of binary arrays (including ES6 classes) and optional type registry.

I still use devalue in Svelte realm but for server-to-server communication typeson is the king.

@Rich-Harris Rich-Harris merged commit 0bbcc96 into Rich-Harris:main Sep 25, 2024
3 checks passed
@Rich-Harris
Copy link
Owner

only took a year to merge, sorry! and thank you, this is awesome

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