Skip to content

Commit 0f93f09

Browse files
committed
Fix maximum stack size error
1 parent e089c2e commit 0f93f09

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- No dependency
99
- Accepts base64url and replace non-url compatible chars with base64 standard chars
1010
- Adds missing padding to base64 string
11+
- Works even on large data
1112
- Uses modern functions and shorter solutions
1213
- Supports ES modules, AMD, CommonJS and IIFE
1314

@@ -79,13 +80,6 @@ async function subscribeUserToPush(registration) {
7980
}
8081
```
8182

82-
## Known issues
83-
84-
```txt
85-
RangeError: Maximum call stack size exceeded
86-
```
87-
This error occurs when using too large data (more than 30 kb) to encode a base64 string (e.g. `uint8ArrayToBase64()` and `arrayBufferToBase64()`).
88-
8983
## Tests
9084

9185
There are no tests for the moment.

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ const base64ToUint8Array = base64String => {
4040
}
4141

4242
const typedArrayToBase64 = typedArray => {
43-
return base64Encode(String.fromCharCode(...typedArray))
43+
const string = typedArray.reduce((data, byte) => {
44+
return data + String.fromCharCode(byte)
45+
}, '')
46+
return base64Encode(string)
4447
}
4548

4649
const uint8ArrayToBase64 = typedArrayToBase64

0 commit comments

Comments
 (0)