4810114 [rkeene@sledge /home/rkeene/tmp]$ cat download-file-test.cr.txt
#! /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
4810115 [rkeene@sledge /home/rkeene/tmp]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2016-01-02 02:54:31