resources/download_buildpack_cache.rb
# Downloads remote location into the specified target file
#
# @param [String] uri location of the remote resource
# @param [String] target filename to copy remote content to
Downloads remote location into the specified target file
Downloads remote location into the specified target file
def download(uri, target)
    @logger.debug "Downloading file to #{target}"
    rich_uri = URI(uri)
    if File.exist?(uri)
      FileUtils.cp uri, target
    else
      proxy(rich_uri).start(rich_uri.host, rich_uri.port, use_ssl: secure?(rich_uri)) do |http|
        request = Net::HTTP::Get.new(rich_uri.request_uri)
        http.request request do |response|
          File.open(target, File::CREAT | File::WRONLY) do |file|
            response.read_body do |chunk|
              file.write(chunk)
            end
          end
        end
      end
    end
  rescue => e
    @logger.error "Unable to download from #{uri}"
    puts e.backtrace
  end
def download ( uri , target ) @logger . debug "Downloading file to #{target}" rich_uri = URI ( uri ) if File . exist? ( uri ) FileUtils . cp uri , target else proxy ( rich_uri ) . start ( rich_uri . host , rich_uri . port , use_ssl : secure? ( rich_uri ) ) do | http | request = Net :: HTTP :: Get . new ( rich_uri . request_uri ) http . request request do | response | File . open ( target , File :: CREAT | File :: WRONLY ) do | file | response . read_body do | chunk | file . write ( chunk ) end end end end end rescue => e @logger . error "Unable to download from #{uri}" puts e . backtrace end
Downloads remote location into the specified target file
Downloads remote location into the specified target file
uri
target
target filename to copy remote content to
target filename to copy remote content to