rubyzip

How do I get a temporary File object (of correct content-type, without writing to disk) directly from a ZipEntry (RubyZip, Paperclip, Rails 3)?

断了今生、忘了曾经 提交于 2019-12-07 06:54:10
问题 I'm currently trying to attach image files to a model directly from a zip file (i.e. without first saving them on a disk). It seems like there should be a clearer way of converting a ZipEntry to a Tempfile or File that can be stored in memory to be passed to another method or object that knows what to do with it. Here's my code: def extract (file = nil) Zip::ZipFile.open(file) { |zip_file| zip_file.each { |image| photo = self.photos.build # photo.image = image # this doesn't work # photo

generate ZIP from generated PDFs with wicked_pdf

独自空忆成欢 提交于 2019-12-06 03:10:46
In my invoice system, I want a backup function to download all invoices at once in one zip file. This system is running on heroku - so it's only possible to save the pdfs temporary. I've the rubyzip and wicked_pdf gem installed. My current code in the controller: def zip_all_bills @bill = Bill.all if @bill.count > 0 t = Tempfile.new("bill_tmp_#{Time.now}") Zip::ZipOutputStream.open(t.path) do |z| @bill.each do |bill| @bills = bill @customer = @bills.customer @customer_name = @customer.name_company_id t = WickedPdf.new.pdf_from_string( render :template => '/bills/printing.html.erb',

How do I get a zipped file's content using the rubyzip library?

孤者浪人 提交于 2019-12-05 06:58:19
I'm trying to extract an uploaded zip file and store its contents in the database, one entry per file. The rubyzip library has nearly no useful documentation. There is an assets table that has key :string (file name) and data :binary (file contents). I'm using the rubyzip library, and have made it as far as this: Zip::ZipFile.open(@file_data.local_path) do |zipfile| zipfile.each do |entry| next if entry.name =~ /__MACOSX/ or entry.name =~ /\.DS_Store/ or !entry.file? asset = self.assets.build asset.key = entry.name asset.data = ?? # what goes here? end end How can I set the data from a

Creating multiple csv-files and download all in one zip-archive using rails

匆匆过客 提交于 2019-12-04 23:42:08
问题 I am looking for a way to create multiple csv files and download them as one zip archive within one request in my rails application. To build the archive I use rubyzip gem - to download it just the rails built-in function send_data. The problem I have is that rubyzip's add-function requires a pathname to load files from. But there is no path as my csv files are created within the same request. Some Code: # controller action to download zip def download_zip zip = @company.download_all send

How to create zip file only in memory in ruby?

青春壹個敷衍的年華 提交于 2019-12-04 04:23:51
问题 I want to create a zip file of all HTML files in a given directory. The zip will be sent as an attachment via email along with the rest of the files from the directory. All email clients I tried so far have trouble reading an email if any attachment is a HTML file, if I send from pony. So I thought I'd zip them. Is there any way to zip the HTML files on the fly but really only in the memory , without using any temp files on Windows platform ? Preferably not using any external program? If I

Creating multiple csv-files and download all in one zip-archive using rails

六月ゝ 毕业季﹏ 提交于 2019-12-03 15:41:33
I am looking for a way to create multiple csv files and download them as one zip archive within one request in my rails application. To build the archive I use rubyzip gem - to download it just the rails built-in function send_data. The problem I have is that rubyzip's add-function requires a pathname to load files from. But there is no path as my csv files are created within the same request. Some Code: # controller action to download zip def download_zip zip = @company.download_all send_data zip, filename: "abc.zip", type: 'application/zip' end # method to create zip def download_all Zip:

How to edit docx with nokogiri and rubyzip

廉价感情. 提交于 2019-12-03 05:19:32
问题 I'm using a combination of rubyzip and nokogiri to edit a .docx file. I'm using rubyzip to unzip the .docx file and then using nokogiri to parse and change the body of the word/document.xml file but ever time I close rubyzip at the end it corrupts the file and I can't open it or repair it. I unzip the .docx file on desktop and check the word/document.xml file and the content is updated to what I changed it to but all the other files are messed up. Could someone help me with this issue? Here

What zip library works well with Ruby 1.9.2?

℡╲_俬逩灬. 提交于 2019-12-02 00:47:26
I used the rubyzip gem in Ruby 1.8.7 before, but I heard rubyzip doesn't work well with ruby 1.9.2. What zip libraries work well with Ruby 1.9.2? Have you actually tried using rubyzip with 1.9.2? Seems to work fine for me: >> RUBY_VERSION #=> "1.9.2" >> require 'zip/zip' #=> true >> Zip::ZipFile.foreach(File.expand_path("~/Downloads/Archive.zip")) { |f| p f } #=> [bartxt, footxt] bar.txt foo.txt I used rubyzip gem in Ruby 1.8.7 also. For Ruby 1.9.x you need to use version 0.9.5 or higher. Works without any problems. I found zip it says it's compatible with 1.9.1 I don't think it would have any

How to create zip file only in memory in ruby?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 21:07:41
I want to create a zip file of all HTML files in a given directory. The zip will be sent as an attachment via email along with the rest of the files from the directory. All email clients I tried so far have trouble reading an email if any attachment is a HTML file, if I send from pony. So I thought I'd zip them. Is there any way to zip the HTML files on the fly but really only in the memory , without using any temp files on Windows platform ? Preferably not using any external program? If I understood right, both methods described in: http://info.michael-simons.eu/2008/01/21/using-rubyzip-to

xlsx compressed by rubyzip not readable by Excel

给你一囗甜甜゛ 提交于 2019-11-30 16:38:30
I am working on writing code which can read/write Excel xlsx files. xlsx files are simply zip archives of several xml files, so in order to test out if I could write a file, I used a gem called rubyzip to unzip the xlsx file and then immediately zip it back up to a new archive, without modifying the data. When I do this, however, I cannot open the new excel file, it is said to be corrupted. Alternatively, if I use Mac OS X's Archive Utility (the native application to handle zip files), and I unzip and re-zip an excel file, the data is not corrupted and I can open the resultant file in Excel. I