Download and write .tar.gz files without corruption

前端 未结 4 1779
一整个雨季
一整个雨季 2021-02-10 13:33

How do you download files, specifically .zip and .tar.gz, with Ruby and write them to the disk?


This question was originally specific to a bug in MacRuby, b

4条回答
  •  时光说笑
    2021-02-10 14:25

    I'd recommend using open-uri in ruby's stdlib.

    require 'open-uri'
    
    open(out_file, 'w') do |out|
      out.write(open(url).read)
    end
    

    http://ruby-doc.org/stdlib/libdoc/open-uri/rdoc/classes/OpenURI/OpenRead.html#M000832

    Make sure you look at the :progress_proc option to open as it looks like you want a progress hook.

提交回复
热议问题