3
運行下面的代碼紅寶石|爲BinRead:無法分配內存(NoMemoryError)
Dir.foreach(FileUtils.pwd()) do |f| if f.end_with?('log') File.open(f) do |file| if File.size(f) > MAX_FILE_SIZE puts f puts file.ctime puts file.mtime # zipping the file orig = f Zlib::GzipWriter.open('arch_log.gz') do |gz| gz.mtime = File.mtime(orig) gz.orig_name = orig gz.write IO.binread(orig) puts "File has been archived" end #deleting the file begin File.delete(f) puts "File has been deleted" rescue Exception => e puts "File #{f} can not be deleted" puts " Error #{e.message}" puts "======= Please remove file manually ==========" end end end end end
而且文件是相當沉重超過1GB。任何幫助,將不勝感激。
我也看到了這個在docs,我想知道是否有另一種更類似於在.NET文件流,使紅寶石不會不斷創造文件句柄上每次調用binread。 – Candide 2012-02-13 08:49:51