Download a file

Hello, actually I’m writing a package manager for Linux with Crystal.
I have just one problem, I don’t understand how to download a file with crystal.

For example if I want to download this archive:

How I can do ?

I’m assuming you just want to save the file to the file system? If so it would be something like:

require "http"

HTTP::Client.get "" do |response|"out.tar.xz", "w") do |file|
    IO.copy response.body_io, file

However, HTTP::Client doesn’t support redirects at the moment, see HTTP::Client: follow redirects · Issue #2721 · crystal-lang/crystal · GitHub, so you will probably have to add in some extra logic to handle that case. I.e. check for response.status.redirection? and if true, look for the location header and make another request before copying the contents to the file.