Rubyzip 未定义方法 'to_binary_dos_time'



当我尝试使用写入模式打开zip文件时,以下消息已记录。

完整错误消息:

undefined method `to_binary_dos_time' for 2017-05-30 15:07:21 +0530:Time

回溯:

    ["/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_entry.rb:286:in `write_local_entry'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_output_stream.rb:147:in `block in update_local_headers'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_entry_set.rb:35:in `each'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_entry_set.rb:35:in `each'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_output_stream.rb:145:in `update_local_headers'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_output_stream.rb:64:in `close'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_output_stream.rb:50:in `ensure in open'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_output_stream.rb:50:in `open'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_file.rb:216:in `block in commit'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_file.rb:324:in `on_success_replace'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_file.rb:214:in `commit'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_file.rb:242:in `close'", 
     "/usr/local/lib/ruby/gems/2.1.0/gems/rubyzip-0.9.9/lib/zip/zip_file.rb:92:in `open'", 
     "/app/zipper_job.rb:36:in `perform'",  

我的代码如下。

path="#{Rails.root}"
new_zip_name= "#{Time.now.to_i.to_s}"
archive = File.join(path,new_zip_name)+'.zip'
Zip::ZipFile.open(archive, 'w') do |zipfile| #Code breaking on this line
    #MY Code
end

任何帮助!!预先感谢。

在尝试将zip条目的日期时间更改为原始文件dateTime时,Rubyzip和RZIP中的类似问题:

zf = Zip::File.open("myzipfile.zip", Zip::File::CREATE)
e = zf.add("myfiletozip.txt","myfiletozip.txt") # will set the zipfile date to now
e.time = File.mtime("myfiletozip.txt") # will set it to the original file's

到目前为止非常好,但是关闭ZIP文件时,PROC会出现相同的错误。问题是"时间="创建"额外"条目中的结构,然后将进一步处理,然后使用丢失的方法。

但是为什么它可以在不设定时间的情况下工作?额外的结构不是构建的,而丢失的方法未使用。那样简单。

to_binary_dos_time/date在宝石中存在:dos_time.rb但是,在我的情况下,GEM程序似乎错误地引用了它们。RB

我的规避。我只是将这两种方法复制到我的代码中,提取了GEM模块DOS_TIME.RB的形式。和 - 奇迹 - 它起作用。宝石程序在本地找到它们,很高兴。

但是,该错误应报告给作者,但我不知道如何。也许有人可以这样做?

def to_binary_dos_time
    (sec / 2) +
      (min << 5) +
      (hour << 11)
end
    
def to_binary_dos_date
    day +
      (month << 5) +
      ((year - 1980) << 9)
end
# source copied out of entry.rb in rubizyp gem, in my case:
# c:Ruby27-x64librubygems2.7.0gemsrubyzip-2.3.0libzipdos_time.rb

我创建了名为 config/initializers/patch.rb 的新文件。

在其中添加了下面的代码,这解决了问题。

Zip::DOSTime.instance_eval do
  def now ; Zip::DOSTime.new() ; end
end

我从这里取的补丁

最新更新