#! /usr/bin/env crystal private def fetchFile(url : String, cacheFileName, hashMethod, hashValue) tempFileName = "#{cacheFileName}-#{Random.rand}-#{Random.rand}-#{Random.rand}" HTTP::Client.get(url) { |result| if result.status_code != 200 raise "Unable to fetch remote file, HTTP status code: #{result.status_code}" end if ! result.body_io? raise "Unable to fetch remote file, no body" end tempFile = File.open(tempFileName, "w"); IO.copy(result.body_io, tempFile.to_fd_io); } validateFile(tempFileName, hashMethod, hashValue) end |