Skip to content

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

Closed

Description

@sholladay

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?

Activity

  1. changed the title [-]uint8ArrayToString is too strict[/-] [+]Allow ArrayBuffer in uint8ArrayToString or add a similar method[/+] on Jul 16, 2024
  2. changed the title [-]Allow ArrayBuffer in uint8ArrayToString or add a similar method[/-] [+]Allow ArrayBuffer in uint8ArrayToString() or add a similar method[/+] on Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions