用回rubyzip, zipruby有bug.

This commit is contained in:
guange 2015-04-03 11:29:37 +08:00
parent 56df5ce9a7
commit 893f6af856
2 changed files with 7 additions and 10 deletions

View File

@ -6,7 +6,7 @@ unless RUBY_PLATFORM =~ /w32/
gem 'iconv'
end
gem 'zipruby', '~> 0.3.6' #performance
gem 'rubyzip'
gem 'delayed_job_active_record'#, :group => :production
gem 'daemons'
gem 'grape', '~> 0.9.0'

View File

@ -1,10 +1,11 @@
require 'zip'
class ZipdownController < ApplicationController
#查找项目(课程)
before_filter :find_project_by_bid_id, :only => [:assort]
#检查权限
#勿删 before_filter :authorize, :only => [:assort,:download_user_homework]
SAVE_FOLDER = "#{Rails.root}/files"
OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip"
OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip"
#统一下载功能
def download
@ -181,23 +182,19 @@ class ZipdownController < ApplicationController
zipfile_name = "#{output_path}/#{rename_zipfile}"
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
Zip::Archive.open(zipfile_name, Zip::CREATE) do |zipfile|
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
files_paths.each do |filename|
flag = true
index = 1
rename_file = File.basename(filename)
rename_file = filename_to_real( File.basename(filename)) if is_attachment
begin
zipfile.add_file(rename_file, filename)
flag = false
zipfile.add(rename_file, filename)
rescue Exception => e
zipfile.add_buffer('FILE_NOTICE.txt', l(:label_file_exist))
zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)}
next
end
end
unless not_exist_file.empty?
zipfile.add_buffer('FILE_LOST.txt', l(:label_file_lost) + not_exist_file.join(',').to_s)
zipfile.get_output_stream('FILE_LOST.txt'){|os| os.write l(:label_file_lost) + not_exist_file.join(',').to_s}
end
end
zipfile_name