mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-27 05:06:42 +00:00
Correctly transform uint8array to string (#696)
* correctly transform uint8array to string * export function
This commit is contained in:
parent
11a6959a24
commit
f4008100e1
@ -15,6 +15,47 @@ export namespace ResponseResultProvider {
|
|||||||
export const JSON: ResponseResultProvider = (response) => response.json();
|
export const JSON: ResponseResultProvider = (response) => response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function Utf8ArrayToStr(array: Uint8Array): string {
|
||||||
|
let out, i, c;
|
||||||
|
let char2, char3;
|
||||||
|
|
||||||
|
out = '';
|
||||||
|
const len = array.length;
|
||||||
|
i = 0;
|
||||||
|
while (i < len) {
|
||||||
|
c = array[i++];
|
||||||
|
switch (c >> 4) {
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
case 5:
|
||||||
|
case 6:
|
||||||
|
case 7:
|
||||||
|
// 0xxxxxxx
|
||||||
|
out += String.fromCharCode(c);
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
case 13:
|
||||||
|
// 110x xxxx 10xx xxxx
|
||||||
|
char2 = array[i++];
|
||||||
|
out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
// 1110 xxxx 10xx xxxx 10xx xxxx
|
||||||
|
char2 = array[i++];
|
||||||
|
char3 = array[i++];
|
||||||
|
out += String.fromCharCode(
|
||||||
|
((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
type ResourceType = 'f' | 'd';
|
type ResourceType = 'f' | 'd';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
@ -275,9 +316,7 @@ export class CreateApi {
|
|||||||
|
|
||||||
// parse the secret file
|
// parse the secret file
|
||||||
const secrets = (
|
const secrets = (
|
||||||
typeof content === 'string'
|
typeof content === 'string' ? content : Utf8ArrayToStr(content)
|
||||||
? content
|
|
||||||
: new TextDecoder().decode(content)
|
|
||||||
)
|
)
|
||||||
.split(/\r?\n/)
|
.split(/\r?\n/)
|
||||||
.reduce((prev, curr) => {
|
.reduce((prev, curr) => {
|
||||||
@ -341,7 +380,7 @@ export class CreateApi {
|
|||||||
const headers = await this.headers();
|
const headers = await this.headers();
|
||||||
|
|
||||||
let data: string =
|
let data: string =
|
||||||
typeof content === 'string' ? content : new TextDecoder().decode(content);
|
typeof content === 'string' ? content : Utf8ArrayToStr(content);
|
||||||
data = await this.toggleSecretsInclude(posixPath, data, 'remove');
|
data = await this.toggleSecretsInclude(posixPath, data, 'remove');
|
||||||
|
|
||||||
const payload = { data: btoa(data) };
|
const payload = { data: btoa(data) };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user