module Oddb2xml::DownloadMethod
Private Instance Methods
download_as(file, option = "w+")
click to toggle source
# File lib/oddb2xml/downloader.rb, line 14 def download_as(file, option = "w+") temp_file = File.join(WORK_DIR, File.basename(file)) @file2save = File.join(DOWNLOADS, File.basename(file)) report_download(@url, @file2save) data = nil FileUtils.makedirs(File.dirname(file), verbose: true) if Oddb2xml.skip_download(file) io = File.open(file, option) data = io.read else begin io = File.open(file, option) data = Oddb2xml.uri_open(@url).read io.sync = true io.write(data) rescue => error puts "error #{error} while fetching #{@url}" ensure io.close if io && !io.closed? # win Oddb2xml.download_finished(temp_file) end end data end