下载并写入.tar.gz文件而不会损坏 [英] Download and write .tar.gz files without corruption

查看:76
本文介绍了下载并写入.tar.gz文件而不会损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Ruby下载文件(尤其是.zip和.tar.gz)并将其写入磁盘?

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


这个问题最初是MacRuby中的一个错误,但是答案与上面的一般问题有关.

使用MacRuby,我发现该文件似乎与参考文件相同(在大小),但档案拒绝提取.我现在要尝试的是: https://gist.github.com/arbales/8203385
谢谢!

推荐答案

我已经使用以下代码成功下载并提取了GZip文件:

I've successfully downloaded and extracted GZip files with this code:

require 'open-uri'
require 'zlib'

open('tarball.tar', 'w') do |local_file|
  open('http://github.com/jashkenas/coffee-script/tarball/master/tarball.tar.gz') do |remote_file|
    local_file.write(Zlib::GzipReader.new(remote_file).read)
  end
end

这篇关于下载并写入.tar.gz文件而不会损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆