- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 rubyzip 在我的应用程序中动态创建 zip 文件。我正在使用 their readme作为起点。我将 gem 添加到我的 Gemfile 中:
gem 'rubyzip'
bundle install
并重新启动了 rails 服务器。
require 'rubygems'
require 'zip'
filename = "#{Time.now.strftime('%y%m%d%H%M%S')}"
input_filenames = ["#{filename}.txt"]
zip_filename = "#{filename}.zip"
Zip::File.open(zip_filename, Zip::File::CREATE) do |zipfile|
input_filenames.each do |f|
zipfile.add(f, directory + '/' + f)
end
end
cannot load such file -- zip
require 'zip/zip'
但它会产生相同的错误。
最佳答案
您可能正在查看一个太新的示例。
如果您正在使用 Rubyzip 0.9.x ,那么你需要关注 this example :
( require "zip/zip"
,然后使用 Zip::ZipFile
而不是 Zip::File
)
require 'zip/zip'
folder = "Users/me/Desktop/stuff_to_zip"
input_filenames = ['image.jpg', 'description.txt', 'stats.csv']
zipfile_name = "/Users/me/Desktop/archive.zip"
Zip::ZipFile.open(zipfile_name, Zip::ZipFile::CREATE) do |zipfile|
input_filenames.each do |filename|
# Two arguments:
# - The name of the file as it will appear in the archive
# - The original file, including the path to find it
zipfile.add(filename, folder + '/' + filename)
end
end
关于ruby-on-rails - rubyzip - 无法加载此类文件 - zip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17956999/
基本上我的日志文件现在看起来像这样: Invalid date/time in zip entry Invalid date/time in zip entry Invalid date/time i
例如使用以下测试树文件夹: - test1 - folder2 - test1 # This is the file rubyzip will break on. - test2 并从 her
我想使用 rubyzip 压缩现有文件: c:\文本文件.txt 到 文本文件.zip 我知道如何将流添加到文本文件: require 'zip/zip' Zip::ZipFile.open("
我想知道与使用 native 操作系统库执行压缩相比,使用 rubyzip 压缩数据时的性能差异是什么。我正在从 URL 获取要压缩的数据,然后使用 ZipOutputStream 创建 zip
我正在尝试解压缩一个包含多个文件的文件,这些文件可能已存在于目标目录中,也可能不存在。似乎默认行为是在文件已存在时抛出异常。 如何解压缩到一个目录并简单地覆盖现有文件? 这是我的代码: begin
我正在尝试使用 rubyzip 在我的应用程序中动态创建 zip 文件。我正在使用 their readme作为起点。我将 gem 添加到我的 Gemfile 中: gem 'rubyzip' 然
我使用 rubyzip-1.2.0 和 ruby 2.2.1 生成一个包含单个文件(在本例中为 python 脚本)的 zip 文件。内容文件没有改变,生成的 zip 字符串的 md5sum
对于我的 Ruby on Rails 项目(Rails 版本 5.1.2),我正在生成图像文件 (png) 并使用 RubyZip gem 将它们下载为 zip 文件。 图像文件不存储在任何目录中。我
当我尝试使用写入模式打开 zip 文件时,系统会记录以下消息。 完整错误信息: undefined method `to_binary_dos_time' for 2017-05-30 15:07:2
我有一个 Ruby 程序,它使用 rubyzip 压缩 XML 文件的目录树。 gem 。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。 我在 rubyzip documenta
在我的 Rails 4.2 应用程序中,我使用 RubyZIP创建类似于以下内容的 Controller 操作: class SomeController < ApplicationControlle
我有一个名为 Image 的模型。图像使用存储在 S3 中的 Dragonfly 附加文件。 我有一个需求,我需要压缩所有图片。 我正在使用: Zip::ZipFile.open(tmp_zip,
我一定是遗漏了一些非常明显的东西,但我似乎无法得到 'zip' gem 工作。我已经用 rubygems 安装了它,就像我用其他许多 gem 一样。 Rubygem 说它在那里,但是当我尝试要求它
我正在从压缩的数据库中读取 blob 数据(文件内容为 CSV 格式)。我的变量的结果如下所示: irb(main):144:0> my_string => "\x1F\x8B\b\x00\xCB'\
我想在压缩后从我的网站下载照片。我正在使用 rubyZip gem,但无法压缩远程文件。以下是场景: 我正在尝试从服务器压缩内容。内容是这样的 http://myApplication.s3.am
我有这段代码,它将一个 zip 文件写入磁盘,读回,上传到 s3,然后删除文件: compressed_file = some_temp_path Zip::ZipOutputStream.open(
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我目前正在尝试将图像文件直接从 zip 文件附加到模型(即,无需先将它们保存在磁盘上)。似乎应该有一种更清晰的方法将 ZipEntry 转换为可以存储在内存中的临时文件或文件,以便传递给另一个知道如何
我是一名优秀的程序员,十分优秀!