summaryrefslogtreecommitdiff
path: root/client-web/source/sw
diff options
context:
space:
mode:
Diffstat (limited to 'client-web/source/sw')
-rw-r--r--client-web/source/sw/download_stream.ts6
-rw-r--r--client-web/source/sw/worker.ts2
2 files changed, 6 insertions, 2 deletions
diff --git a/client-web/source/sw/download_stream.ts b/client-web/source/sw/download_stream.ts
index 0ba6289..52d9fad 100644
--- a/client-web/source/sw/download_stream.ts
+++ b/client-web/source/sw/download_stream.ts
@@ -4,7 +4,7 @@ import { SW } from "./init.ts"
function FallbackStreamDownload(size: number, filename?: string, progress?: (position: number) => void) {
log({ scope: "*", warn: true }, "downloading to memory because serviceworker is not available")
let position = 0
- const buffer = new Uint8Array(size)
+ let buffer = new Uint8Array(size)
return {
close() {
const a = document.createElement("a")
@@ -12,6 +12,7 @@ function FallbackStreamDownload(size: number, filename?: string, progress?: (pos
a.download = filename ?? "file"
a.click()
},
+ abort() { buffer = new Uint8Array(); /* have fun gc */ },
write(chunk: Blob) {
const reader = new FileReader();
reader.onload = function (event) {
@@ -57,6 +58,9 @@ export function StreamDownload({ size, filename, cancel, progress }: {
close() {
port1.postMessage("end")
},
+ abort() {
+ port1.postMessage("abort")
+ },
write(chunk: Blob) {
const reader = new FileReader();
reader.onload = function (event) {
diff --git a/client-web/source/sw/worker.ts b/client-web/source/sw/worker.ts
index 327aba0..94db220 100644
--- a/client-web/source/sw/worker.ts
+++ b/client-web/source/sw/worker.ts
@@ -39,7 +39,7 @@ function port_to_readable(port: MessagePort): ReadableStream {
start(controller) {
console.log("ReadableStream started");
port.onmessage = event => {
- if (event.data === "end") { controller.close() }
+ if (event.data === "end") controller.close()
else if (event.data === "abort") controller.error("aborted")
else controller.enqueue(event.data)
}