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();
}