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

Allow ArrayBuffer in uint8ArrayToString() or add a similar method #14

Closed
sholladay opened this issue Jul 16, 2024 · 0 comments
Closed

Comments

@sholladay
Copy link

sholladay commented Jul 16, 2024

I naively replaced new TextDecoder(data).decode() with uint8ArrayToString(data), in hopes of making use of the decoder cache and keeping my code concise and consistent (i.e. always use the library's decoder or always my own, not mix and match).

However, I immediately ran into an error:

error: Uncaught (in promise) TypeError: Expected `Uint8Array`, got `object

This was caused by the fact that data was not a Uint8Array but rather an ArrayBuffer, as returned by the Web Crypto API encrypt() / decrypt() methods.

Given the function name, I suppose I should've anticipated this, but because TextDecoder handles ArrayBuffers, I thought it would be fine.

How necessary is the assertion in that function? Maybe there could be a new method or option for bypassing that assertion?

@sholladay sholladay changed the title uint8ArrayToString is too strict Allow ArrayBuffer in uint8ArrayToString or add a similar method Jul 16, 2024
@sholladay sholladay changed the title Allow ArrayBuffer in uint8ArrayToString or add a similar method Allow ArrayBuffer in uint8ArrayToString() or add a similar method Jul 16, 2024
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

No branches or pull requests

1 participant