File tree 1 file changed +8
-6
lines changed
1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -22,15 +22,17 @@ export const toBase64 = (data: string | Uint8Array | null | undefined): string =
22
22
23
23
export const fromBase64 = ( str : string ) : Uint8Array => {
24
24
if ( typeof ( globalThis as any ) . Buffer !== 'undefined' ) {
25
- return new Uint8Array ( ( globalThis as any ) . Buffer . from ( str , 'base64' ) ) ;
25
+ const buf = ( globalThis as any ) . Buffer . from ( str , 'base64' ) ;
26
+ return new Uint8Array ( buf . buffer , buf . byteOffset , buf . byteLength ) ;
26
27
}
27
28
28
29
if ( typeof atob !== 'undefined' ) {
29
- return new Uint8Array (
30
- atob ( str )
31
- . split ( '' )
32
- . map ( ( c ) => c . charCodeAt ( 0 ) ) ,
33
- ) ;
30
+ const bstr = atob ( str ) ;
31
+ const buf = new Uint8Array ( bstr . length ) ;
32
+ for ( let i = 0 ; i < bstr . length ; i ++ ) {
33
+ buf [ i ] = bstr . charCodeAt ( i ) ;
34
+ }
35
+ return buf ;
34
36
}
35
37
36
38
throw new GitpodError ( 'Cannot decode base64 string; Expected `Buffer` or `atob` to be defined' ) ;
You can’t perform that action at this time.
0 commit comments