@@ -2,6 +2,7 @@ import { MaybePromise } from '@theia/core/lib/common/types';
2
2
import { inject , injectable } from '@theia/core/shared/inversify' ;
3
3
import { fetch } from 'cross-fetch' ;
4
4
import { SketchesService } from '../../common/protocol' ;
5
+ import { unit8ArrayToString } from '../../common/utils' ;
5
6
import { ArduinoPreferences } from '../arduino-preferences' ;
6
7
import { AuthenticationClientService } from '../auth/authentication-client-service' ;
7
8
import { SketchCache } from '../widgets/cloud-sketchbook/cloud-sketch-cache' ;
@@ -19,49 +20,6 @@ export namespace ResponseResultProvider {
19
20
export const JSON : ResponseResultProvider = ( response ) => response . json ( ) ;
20
21
}
21
22
22
- // TODO: check if this is still needed: https://github.com/electron/electron/issues/18733
23
- // The original issue was reported for Electron 5.x and 6.x. Theia uses 15.x
24
- export function Utf8ArrayToStr ( array : Uint8Array ) : string {
25
- let out , i , c ;
26
- let char2 , char3 ;
27
-
28
- out = '' ;
29
- const len = array . length ;
30
- i = 0 ;
31
- while ( i < len ) {
32
- c = array [ i ++ ] ;
33
- switch ( c >> 4 ) {
34
- case 0 :
35
- case 1 :
36
- case 2 :
37
- case 3 :
38
- case 4 :
39
- case 5 :
40
- case 6 :
41
- case 7 :
42
- // 0xxxxxxx
43
- out += String . fromCharCode ( c ) ;
44
- break ;
45
- case 12 :
46
- case 13 :
47
- // 110x xxxx 10xx xxxx
48
- char2 = array [ i ++ ] ;
49
- out += String . fromCharCode ( ( ( c & 0x1f ) << 6 ) | ( char2 & 0x3f ) ) ;
50
- break ;
51
- case 14 :
52
- // 1110 xxxx 10xx xxxx 10xx xxxx
53
- char2 = array [ i ++ ] ;
54
- char3 = array [ i ++ ] ;
55
- out += String . fromCharCode (
56
- ( ( c & 0x0f ) << 12 ) | ( ( char2 & 0x3f ) << 6 ) | ( ( char3 & 0x3f ) << 0 )
57
- ) ;
58
- break ;
59
- }
60
- }
61
-
62
- return out ;
63
- }
64
-
65
23
type ResourceType = 'f' | 'd' ;
66
24
67
25
@injectable ( )
@@ -333,7 +291,7 @@ export class CreateApi {
333
291
334
292
// parse the secret file
335
293
const secrets = (
336
- typeof content === 'string' ? content : Utf8ArrayToStr ( content )
294
+ typeof content === 'string' ? content : unit8ArrayToString ( content )
337
295
)
338
296
. split ( / \r ? \n / )
339
297
. reduce ( ( prev , curr ) => {
@@ -397,7 +355,7 @@ export class CreateApi {
397
355
const headers = await this . headers ( ) ;
398
356
399
357
let data : string =
400
- typeof content === 'string' ? content : Utf8ArrayToStr ( content ) ;
358
+ typeof content === 'string' ? content : unit8ArrayToString ( content ) ;
401
359
data = await this . toggleSecretsInclude ( posixPath , data , 'remove' ) ;
402
360
403
361
const payload = { data : btoa ( data ) } ;
0 commit comments