Created
December 31, 2013 23:43
-
-
Save arbales/8203385 to your computer and use it in GitHub Desktop.
Illustrates downloading a file in MacRuby. —
From a question on StackOverflow about the corruption of downloaded files in MacRuby.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def download_request(url, filePath:path, progressIndicator:progressBar) | |
file = File.open(path, "w+") | |
begin | |
Net::HTTP.get_response URI.parse(url) do |response| | |
if response['Location']!=nil | |
puts 'Direct to: ' + response['Location'] | |
return download_request(response['Location'], filePath:path, progressIndicator:progressBar) | |
end | |
# some stuff | |
response.read_body do |segment| | |
file.write(segment) | |
# some progress stuff. | |
end | |
end | |
ensure | |
file.close | |
end | |
end | |
download_request("http://github.com/jashkenas/coffee-script/tarball/master", filePath:"tarball.tar.gz", progressIndicator:nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment