Streaming download throws `Bad resource ID`
Anyone have an idea why this errors when closing the file even though the download was successfully written to the file?
deno 1.45.2
deno 1.45.2
const res = await fetch(url);
if (!res.ok) {
throw new Error(`Got error ${res.status} ${res.statusText}`);
}
const body = res.body;
if (!body) {
throw new Error(`Got no body`);
}
const file = await Deno.create(path);
try {
await body.pipeTo(file.writable);
} catch (e) {
await Deno.remove(path);
throw new Error(`Download interrupted ${e}`);
} finally {
file.close();
}const res = await fetch(url);
if (!res.ok) {
throw new Error(`Got error ${res.status} ${res.statusText}`);
}
const body = res.body;
if (!body) {
throw new Error(`Got no body`);
}
const file = await Deno.create(path);
try {
await body.pipeTo(file.writable);
} catch (e) {
await Deno.remove(path);
throw new Error(`Download interrupted ${e}`);
} finally {
file.close();
}error: Uncaught (in promise) BadResource: Bad resource ID
file.close();
^
at FsFile.close (ext:deno_fs/30_fs.js:743:10)
at loadFile (file:///foobar/loadFile.ts:142:16)
at eventLoopTick (ext:core/01_core.js:168:7)
at async file:///foobar/main.ts:42:7error: Uncaught (in promise) BadResource: Bad resource ID
file.close();
^
at FsFile.close (ext:deno_fs/30_fs.js:743:10)
at loadFile (file:///foobar/loadFile.ts:142:16)
at eventLoopTick (ext:core/01_core.js:168:7)
at async file:///foobar/main.ts:42:7