-
Notifications
You must be signed in to change notification settings - Fork 2
/
Utils.ts
37 lines (34 loc) · 1.04 KB
/
Utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import axios, { AxiosResponse } from "axios";
export default class Utils {
static async fetchRemoteData(url: string) {
try {
const response: AxiosResponse<any> = await axios.get(url, {
responseType: "arraybuffer",
});
return new Uint8Array(response.data);
} catch (error: any) {
throw new Error("Error in Utils.fetchRemoteData: ", error);
}
}
static async fetchRemoteDataCallback(url: string, callback: any) {
try {
const response: any = await axios
.get(url, { responseType: "arraybuffer" })
.then((response: any) => {
const data = new Uint8Array(response.data);
console.log(data);
callback(response);
});
return response;
} catch (error: any) {
throw new Error("Error in Utils.fetchRemoteDataCallback: ", error);
}
}
static string2Uint8Data(string: string) {
const data = new Uint8Array(string.length);
for (let i = 0; i < data.length; i++) {
data[i] = string.charCodeAt(i) & 0xff;
}
return data;
}
}