RubyZip: индикация процесса архивирования - PullRequest
1 голос
/ 01 июля 2011

Я добавляю тонны файлов в мой архив, это выглядит так:

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 минут).*

Как я могу указать, что на самом деле происходит с rubyzip gem (на самом деле я хочу показать процент как current_file_number/total_files_count).

1 Ответ

1 голос
/ 01 июля 2011

Вы можете переопределить 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|
...