Created
January 12, 2012 21:32
-
-
Save mkrogh/1603268 to your computer and use it in GitHub Desktop.
rubyzip + open-uri (1.8.7 and 1.9.2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "open-uri" | |
require "zip/zip" | |
img_url = "http://jquery.com/demo/thickbox/images/plant4.jpg" | |
img_name = "plant4.jpg" | |
#this works in 1.8.7, but not in 1.9.2: | |
Zip::ZipFile.open("test.zip", Zip::ZipFile::CREATE) do |zipfile| | |
img = open(img_url) | |
zipfile.add(img_name, img.path) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "open-uri" | |
require "zip/zip" | |
#Quick note, jpg works, png does not.. | |
img_url = "http://jquery.com/demo/thickbox/images/plant4.jpg" | |
img_name = "plant4.jpg" | |
#In ruby 1.9.2 this is possible: | |
Zip::ZipFile.open("test.zip", Zip::ZipFile::CREATE) do |zipfile| | |
img = open(img_url) | |
zipfile.add(img_name, img) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment