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 => {
2020 return Buffer . from ( data , 'base64' ) . toString ( 'binary' )
2121}
2222
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+
2331const base64ToUint8Array = base64String => {
2432 // base64 sanitizing
2533 const base64 = base64urlToBase64 ( base64String )
@@ -32,10 +40,7 @@ const base64ToUint8Array = base64String => {
3240}
3341
3442const 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 ) )
3944}
4045
4146const uint8ArrayToBase64 = typedArrayToBase64
You can’t perform that action at this time.
0 commit comments