RubyZip:归档过程指示

发布于 2024-11-17 19:53:33 字数 496 浏览 4 评论 0原文

我正在将大量文件添加到我的存档中,它看起来像这样:

print "Starting ..."
Zip::ZipFile.open(myarchive, 'w') do |zipfile|
  my_tons_of_files.each do |file|
    print "Adding #{file.filename} to archive ... \r"
    # ...
  end
  print "\n Saving archive"
  # !!! -> waiting about 10-15 minutes
  # but I want to show the percentage of completed job
end

将所有文件添加到我的存档中后,它开始压缩所有文件(大约 10-15 分钟)。

我如何指示 ruby​​zip gem 实际发生的情况(实际上我想显示百分比,例如 current_file_number/total_files_count)。

I am adding tons of file to my archive it looks like this:

print "Starting ..."
Zip::ZipFile.open(myarchive, 'w') do |zipfile|
  my_tons_of_files.each do |file|
    print "Adding #{file.filename} to archive ... \r"
    # ...
  end
  print "\n Saving archive"
  # !!! -> waiting about 10-15 minutes
  # but I want to show the percentage of completed job
end

After all files are added to my archive it starts to compress them all (about 10-15 minutes).

How can I indicate what is actually going on with rubyzip gem (actually I want to show percentage like current_file_number/total_files_count).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奈何桥上唱咆哮 2024-11-24 19:53:33

您可以覆盖 Zip::ZipFile.commit:

require 'zip'
require 'zip/zipfilesystem'

module Zip
class ZipFile

    def commit
     return if ! commit_required?
      on_success_replace(name) {
        |tmpFile|
        ZipOutputStream.open(tmpFile) {
          |zos|

          total_files = @entrySet.length
          current_files = 1
          @entrySet.each do |e|
             puts "Current file: #{current_files}, Total files: #{total_files}"
             current_files += 1
             e.write_to_zip_output_stream(zos)
          end
          zos.comment = comment
        }
        true
      }
      initialize(name)
    end

end
end

print "Starting ..."
Zip::ZipFile.open(myarchive, 'w') do |zipfile|

You can override Zip::ZipFile.commit:

require 'zip'
require 'zip/zipfilesystem'

module Zip
class ZipFile

    def commit
     return if ! commit_required?
      on_success_replace(name) {
        |tmpFile|
        ZipOutputStream.open(tmpFile) {
          |zos|

          total_files = @entrySet.length
          current_files = 1
          @entrySet.each do |e|
             puts "Current file: #{current_files}, Total files: #{total_files}"
             current_files += 1
             e.write_to_zip_output_stream(zos)
          end
          zos.comment = comment
        }
        true
      }
      initialize(name)
    end

end
end

print "Starting ..."
Zip::ZipFile.open(myarchive, 'w') do |zipfile|
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文