[英]RubyZip: archiving process indication
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).将所有文件添加到我的存档后,它开始将它们全部压缩(大约 10-15 分钟)。
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
).我如何指示rubyzip gem
的实际情况(实际上我想显示像current_file_number/total_files_count
这样的百分比)。
You can override Zip::ZipFile.commit:您可以覆盖 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|
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.