Skip to content

Commit

Permalink
0.0.561
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansglazunov committed Sep 22, 2024
1 parent 4d1e638 commit 8227b06
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export type { ClientHandlerRendererProps, ClientHandlerProps } from "./imports/c

export { Packages } from "./imports/packages.js";

export { Files, useFiles } from "./imports/files.js";
export { Files, useFiles, base64ToFile, fileToBase64 } from "./imports/files.js";
23 changes: 23 additions & 0 deletions imports/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,26 @@ export function useFiles({
});
return dropzone;
}

export function base64ToFile(dataurl, filename) {
var arr = dataurl.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[arr.length - 1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, { type: mime });
}

export function fileToBase64(file) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
console.log(reader.result);
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deep-foundation/deeplinks",
"version": "0.0.560",
"version": "0.0.561",
"license": "Unlicense",
"type": "module",
"main": "import.js",
Expand Down

0 comments on commit 8227b06

Please sign in to comment.