I am working on writing a file (Ruby 1.8.6, which cannot be changed) from folders. Now before there were fewer lines in the file, which was perfectly zipped. But when I add more content to the zip, it gives me a file that looks like corrupted content. This is a sort of sorting a long file. Files with more than 5000 lines.
Is there a way to get the full content without corruption.
Content like
Family = 1,1,1
now Fam
Here is the code with the class
def download FileUtils.rm_rf Dir.glob("#{RAILS_ROOT}/#{params[:id]}/xx.zip") zip_them_all = ZipThemAll.new("#{RAILS_ROOT}/#{params[:id]}/xxx.zip","#{RAILS_ROOT}/#{params[:id]}/") zip_them_all.zip end class ZipThemAll attr_accessor :list_of_file_paths, :zip_file_path def initialize( zip_file_path, list_of_file_paths ) @zip_file_path = zip_file_path list_of_file_paths = [list_of_file_paths] if list_of_file_paths.class == String @list_of_file_paths = list_of_file_paths end def zip zip_file = Zip::ZipFile.open(self.zip_file_path, Zip::ZipFile::CREATE) self.zip_em_all( zip_file, @list_of_file_paths ) zip_file.close end def zip_em_all( zip_file, file_list, sub_directory=nil ) file_list.each do | file_path | if File.exists?file_path if File.directory?( file_path ) file_directory_list = [] # Find.find( file_path ) do | path | file_directory_list = Dir.entries( file_path ) file_directory_list.delete(".") file_directory_list.delete("..") file_directory_list = file_directory_list.inject([]) do | result, path | result << file_path + "/" + path result end self.zip_em_all( zip_file, file_directory_list, (sub_directory == nil ? '.' : sub_directory) + "/" + File.basename(file_path) ) else file_name = File.basename( file_path ) if sub_directory != nil if zip_file.find_entry( sub_directory ) == nil dir = zip_file.mkdir( sub_directory ) end file_name = sub_directory + "/" + file_name end if zip_file.find_entry( file_name ) zip_file.replace( file_name, file_path ) else zip_file.add( file_name, file_path) end end else puts "Warning: file #{file_path} does not exist" end end end end
source share