aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/lib')
-rw-r--r--app/src/lib/ts/download.ts59
-rw-r--r--app/src/lib/ts/truncate.worker.ts11
-rw-r--r--app/src/lib/types/truncate-worker.ts6
3 files changed, 38 insertions, 38 deletions
diff --git a/app/src/lib/ts/download.ts b/app/src/lib/ts/download.ts
index a6167d7..16712fb 100644
--- a/app/src/lib/ts/download.ts
+++ b/app/src/lib/ts/download.ts
@@ -1,33 +1,34 @@
// Yoinked from https://web.dev/patterns/files/save-a-file/ for the polyfill
export default async function saveFile(blob: ArrayBuffer, suggestedName: string | undefined) {
- const supportsFSAccess = 'showSaveFilePicker' in window &&
- (() => {
- try {
- return window.self === window.top;
- } catch {
- return false;
- }
- })();
+ const supportsFSAccess =
+ 'showSaveFilePicker' in window &&
+ (() => {
+ try {
+ return window.self === window.top;
+ } catch {
+ return false;
+ }
+ })();
- if (supportsFSAccess) {
- try {
- const handle = await window.showSaveFilePicker({
- suggestedName: suggestedName,
- })
- const writable = await handle.createWritable();
- await writable.write(blob);
- await writable.close();
- } catch (err: unknown) {
- // TypeScript
- if ((err as Error)?.name !== 'AbortError') {
- console.error(err);
- }
- }
- } else {
- const anchor = document.createElement('a');
- anchor.download = suggestedName ?? 'truncated';
- anchor.href = URL.createObjectURL(new Blob([blob]));
- anchor.click();
- }
-} \ No newline at end of file
+ if (supportsFSAccess) {
+ try {
+ const handle = await window.showSaveFilePicker({
+ suggestedName: suggestedName
+ });
+ const writable = await handle.createWritable();
+ await writable.write(blob);
+ await writable.close();
+ } catch (err: unknown) {
+ // TypeScript
+ if ((err as Error)?.name !== 'AbortError') {
+ console.error(err);
+ }
+ }
+ } else {
+ const anchor = document.createElement('a');
+ anchor.download = suggestedName ?? 'truncated';
+ anchor.href = URL.createObjectURL(new Blob([blob]));
+ anchor.click();
+ }
+}
diff --git a/app/src/lib/ts/truncate.worker.ts b/app/src/lib/ts/truncate.worker.ts
index 52eebb7..ad00011 100644
--- a/app/src/lib/ts/truncate.worker.ts
+++ b/app/src/lib/ts/truncate.worker.ts
@@ -1,10 +1,9 @@
import type { TruncateRequest, TruncateResponse } from '../types/truncate-worker';
-
onmessage = async (message: MessageEvent<TruncateRequest>) => {
- const file = message.data.file;
- const buffer = await file.arrayBuffer();
- const truncated = buffer.slice(0, message.data.size);
+ const file = message.data.file;
+ const buffer = await file.arrayBuffer();
+ const truncated = buffer.slice(0, message.data.size);
- postMessage({ file: truncated } as TruncateResponse);
-} \ No newline at end of file
+ postMessage({ file: truncated } as TruncateResponse);
+};
diff --git a/app/src/lib/types/truncate-worker.ts b/app/src/lib/types/truncate-worker.ts
index 9b1872f..7052d17 100644
--- a/app/src/lib/types/truncate-worker.ts
+++ b/app/src/lib/types/truncate-worker.ts
@@ -1,8 +1,8 @@
export type TruncateRequest = {
- file: File,
- size: number,
+ file: File;
+ size: number;
};
export type TruncateResponse = {
- file: ArrayBuffer,
+ file: ArrayBuffer;
};