Skip to content

Instantly share code, notes, and snippets.

@arbales
Created December 31, 2013 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arbales/8203385 to your computer and use it in GitHub Desktop.
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.
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