From 83e0e01e36053cf84244aa7046d53ab2cf26c251 Mon Sep 17 00:00:00 2001 From: FND Date: Tue, 26 Mar 2024 17:57:27 +0100 Subject: [PATCH] fixed use of `revokeObjectURL` as exposed by Deno: https://github.com/denoland/deno/issues/23085 this is an annoyingly subtle mistake, but doesn't quite warrant an update announcement --- content/articles/web_fs/demo.html | 4 ++-- content/articles/web_fs/index.md | 6 +++--- content/snippets/virtual_modules/demo.html | 5 +++-- content/snippets/virtual_modules/index.md | 5 +++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/content/articles/web_fs/demo.html b/content/articles/web_fs/demo.html index 2fcfd4f..941d561 100644 --- a/content/articles/web_fs/demo.html +++ b/content/articles/web_fs/demo.html @@ -140,7 +140,7 @@

Local Notes

function generateDownloadLink(filename, content, type = "text/plain") { // create virtual document try { - var blob = new Blob([content], { type }); + let blob = new Blob([content], { type }); var uri = URL.createObjectURL(blob); } catch(err) { // fallback for ancient browsers uri = `data:${type},${encodeURIComponent(content)}`; @@ -152,7 +152,7 @@

Local Notes

el.setAttribute("href", uri); return { el, - release: () => blob && URL.revokeObjectURL(blob) + release: () => uri && URL.revokeObjectURL(uri) }; } diff --git a/content/articles/web_fs/index.md b/content/articles/web_fs/index.md index 953c742..c8e58d1 100644 --- a/content/articles/web_fs/index.md +++ b/content/articles/web_fs/index.md @@ -106,9 +106,9 @@ download the respective file instead: ```javascript function generateDownloadLink(filename, content, type = "text/plain") { // create virtual document - let blob, uri; + let uri; try { - blob = new Blob([content], { type }); + let blob = new Blob([content], { type }); uri = URL.createObjectURL(blob); } catch(err) { // fallback for ancient browsers uri = `data:${type},${encodeURIComponent(content)}`; @@ -120,7 +120,7 @@ function generateDownloadLink(filename, content, type = "text/plain") { el.setAttribute("href", uri); return { el, - release: () => blob && URL.revokeObjectURL(blob) + release: () => uri && URL.revokeObjectURL(uri) }; } ``` diff --git a/content/snippets/virtual_modules/demo.html b/content/snippets/virtual_modules/demo.html index 3c82b05..df04099 100644 --- a/content/snippets/virtual_modules/demo.html +++ b/content/snippets/virtual_modules/demo.html @@ -92,9 +92,10 @@

Worker Sample

function code2uri(txt, type = "text/javascript") { let blob = new Blob([txt], { type }); + let uri = URL.createObjectURL(blob); return { - uri: URL.createObjectURL(blob), - release: () => URL.revokeObjectURL(blob) + uri, + release: () => URL.revokeObjectURL(uri) }; } diff --git a/content/snippets/virtual_modules/index.md b/content/snippets/virtual_modules/index.md index 2940207..eca9a24 100644 --- a/content/snippets/virtual_modules/index.md +++ b/content/snippets/virtual_modules/index.md @@ -19,9 +19,10 @@ respective source code: ```javascript function code2uri(txt, type = "text/javascript") { let blob = new Blob([txt], { type }); + let uri = URL.createObjectURL(blob); return { - uri: URL.createObjectURL(blob), - release: () => URL.revokeObjectURL(blob) + uri, + release: () => URL.revokeObjectURL(uri) }; } ```