lib/down.rb in down-1.1.0 vs lib/down.rb in down-2.0.0
- old
+ new
@@ -9,17 +9,17 @@
class NotFound < Error; end
module_function
def download(url, options = {})
- url = URI.encode(URI.decode(url))
+ uri = URI.parse(url)
max_size = options.delete(:max_size)
progress = options.delete(:progress)
timeout = options.delete(:timeout)
- downloaded_file = URI(url).open({
+ downloaded_file = uri.open({
"User-Agent" => "Down/1.0.0",
content_length_proc: proc { |size|
raise Down::TooLarge if size && max_size && size > max_size
},
progress_proc: proc { |current_size|
@@ -34,18 +34,18 @@
# less than 10 KB, so if it happens we convert it back to Tempfile. We want
# to do this with a Tempfile as well, because open-uri doesn't preserve the
# file extension, so we want to run it against #copy_to_tempfile which
# does.
open_uri_file = downloaded_file
- downloaded_file = copy_to_tempfile(URI(url).path, open_uri_file)
+ downloaded_file = copy_to_tempfile(uri.path, open_uri_file)
OpenURI::Meta.init downloaded_file, open_uri_file
downloaded_file.extend DownloadedFile
downloaded_file
rescue => error
raise if error.is_a?(Down::Error)
- raise Down::NotFound, error.message
+ raise Down::NotFound, "#{error.class}: #{error.message}"
end
def copy_to_tempfile(basename, io)
tempfile = Tempfile.new(["down", File.extname(basename)], binmode: true)
if io.is_a?(OpenURI::Meta) && io.is_a?(Tempfile)