Skip to content

Instantly share code, notes, and snippets.

@manuelbieh
Last active November 18, 2024 15:12
Show Gist options
  • Save manuelbieh/e44c3a2c0586d4df05f9c03b9060c75e to your computer and use it in GitHub Desktop.
Save manuelbieh/e44c3a2c0586d4df05f9c03b9060c75e to your computer and use it in GitHub Desktop.
Deno File Download

Use Deno to download files from the internet.

Usage

deno run --allow-net --allow-write download.ts [url] [filename]

Example

 deno run --allow-net --allow-write \
   https://gist.githubusercontent.com/manuelbieh/e44c3a2c0586d4df05f9c03b9060c75e/raw/32c5b224d0b33b44825e6c47856263541027a05a/download.ts \
   https://www.google.de/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png \
   google-logo.png
const download = async (url: string, filename: string) => {
const data = (await fetch(url)).arrayBuffer();
console.log(`Saving ${url} to ${filename}`);
return Deno.writeFile(filename, new Uint8Array(await data));
};
const [url, filename] = Deno.args;
if (!url || !filename) {
throw new Error('url or filename is missing.');
}
await download(url, filename);
@ooker777
Copy link

There is also an JSR module: https://jsr.io/@chiba/wget

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment