2011-07-01 2 views
1

내가 내 아카이브 파일의 톤을 추가하고 그것은 다음과 같습니다 : 모든 파일이 내 아카이브에 추가됩니다 그들에게 모든 (10-15 분) 압축하기 시작하면RubyZip : 아카이빙 프로세스 표시

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 

.

사실 실제로 rubyzip gem (실제로는 current_file_number/total_files_count과 같은 비율을 표시하려고합니다)로 무엇이 진행되고 있는지 나타낼 수 있습니다.

+0

당신이 건설되고있다으로 zip 파일의 크기에 눈을 유지하기 위해 스레드를 시작 생각 해 봤나? 그게 당신에게 "2342의 파일 11 압축"을주지는 않겠지 만 그것이 뭔가를하고 있음을 당신에게 알려줄 것입니다. –

+0

@mu는 너무 짧고 똑똑한 아이디어, 고맙습니다. – fl00r

답변

1

당신은 우편 번호를 대체 할 수 있습니다 : 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| 
관련 문제