Skip to content

Commit

Permalink
Convert a base64 encoded string to an uint8 array
Browse files Browse the repository at this point in the history
  • Loading branch information
phuocng committed Nov 11, 2021
1 parent 99f8c99 commit 98a9674
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: Convert a base64 encoded string to an uint8 array
category: String
---

**JavaScript version**

```js
const base64ToUint8 = (str) => Uint8Array.from(atob(str), (c) => c.charCodeAt(0));
```

**TypeScript version**

```js
const base64ToUint8 = (str: string): Uint8Array => Uint8Array.from(atob(str), (c) => c.charCodeAt(0));
```

**See also**

- [Convert an uint8 array to a base64 encoded string](/string/convert-an-uint8-array-to-a-base64-encoded-string)
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ const uint8ToBase64 = (arr: Uint8Array): string =>
// For Node.js
const uint8ToBase64 = (arr: Uint8Array): string => Buffer.from(arr).toString('base64');
```

**See also**

- [Convert a base64 encoded string to an uint8 array](/string/convert-a-base64-encoded-string-to-an-uint8-array)

0 comments on commit 98a9674

Please sign in to comment.