Crystal lang how to get binary file from http
问题 In Ruby: require 'open-uri' download = open('http://example.com/download.pdf') IO.copy_stream(download, '~/my_file.pdf') How to do the same in Crystal? 回答1: We can do the following: require "http/client" HTTP::Client.get("http://example.org") do |response| File.write("example.com.html", response.body_io) end This writes just the response without any HTTP headers to the file. File.write is also smart enough to not download the entire file into memory first, but to write to the file as it reads