@buerokratt-ria/common-gui-components 0.0.33 → 0.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/services/file.ts +13 -2
package/package.json
CHANGED
package/services/file.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Converts a base64 string to a Uint8Array (browser-compatible alternative to Buffer)
|
|
3
|
+
*/
|
|
4
|
+
const base64ToUint8Array = (base64: string): Uint8Array<ArrayBuffer> => {
|
|
5
|
+
const binaryString = atob(base64);
|
|
6
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
7
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
8
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
9
|
+
}
|
|
10
|
+
return bytes;
|
|
11
|
+
};
|
|
2
12
|
|
|
3
13
|
export const saveFile = async (base64String: string, fileName: `${string}.${string}`, type: string) => {
|
|
4
|
-
const
|
|
14
|
+
const bytes = base64ToUint8Array(base64String);
|
|
15
|
+
const blob = new Blob([bytes], {
|
|
5
16
|
type: type,
|
|
6
17
|
});
|
|
7
18
|
|