1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Denoでファイルダウンロードをする

Posted at

最近Denoでファイルダウンロードをする必要があったので、実装しました。
てきとうに書いたのであまり良くない書き方をしているかもなので、その時はコメントでご指摘ください。

結論

import ky from "https://deno.land/x/ky/index.js";

const url = "https://raw.githubusercontent.com/denolib/high-res-deno-logo/master/deno_hr.png";
const path = "deno.png";

ky.get(url)
    .arrayBuffer()
    .then(buffer => {
        Deno.writeFileSync(path, new Uint8Array(buffer));
    });

console.log("Completed download!");

kyでファイルを取得し、ArrayBufferからUint8Arrayにしたあと保存しています。

やってみる

try.gif

無事にダウンロードできました。

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?