我想在Rails中创建一个临时的.zip文件。为了创建zip文件,我正在使用rubyzip
gem。
目前我正在这样做:
zfname = Tempfile.new(['somename','.zip'], Rails.root.to_s + '/tmp/')
Zip::ZipFile.open(zfname.path, Zip::ZipFile::CREATE) do |zipfile|
zipfile.add(file, basepath + file)
end
这会生成以下错误:
Zip::ZipError: Zip end of central directory signature not found
是否可以使用Tempfile
压缩文件?如果可以,下面的代码有什么问题?