File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ const base64Decode = data => {
20
20
return Buffer . from ( data , 'base64' ) . toString ( 'binary' )
21
21
}
22
22
23
+ const base64Encode = data => {
24
+ if ( runningOnBrowser ) {
25
+ return btoa ( data )
26
+ }
27
+ // btoa polyfill for Node
28
+ return Buffer . from ( data ) . toString ( 'base64' )
29
+ }
30
+
23
31
const base64ToUint8Array = base64String => {
24
32
// base64 sanitizing
25
33
const base64 = base64urlToBase64 ( base64String )
@@ -32,10 +40,7 @@ const base64ToUint8Array = base64String => {
32
40
}
33
41
34
42
const typedArrayToBase64 = typedArray => {
35
- if ( runningOnBrowser ) {
36
- return btoa ( String . fromCharCode ( ...typedArray ) )
37
- }
38
- return Buffer . from ( typedArray ) . toString ( 'base64' )
43
+ return base64Encode ( String . fromCharCode ( ...typedArray ) )
39
44
}
40
45
41
46
const uint8ArrayToBase64 = typedArrayToBase64
You can’t perform that action at this time.
0 commit comments