Skip to content

Instantly share code, notes, and snippets.

@mkrogh
Created January 12, 2012 21:32
Show Gist options
  • Save mkrogh/1603268 to your computer and use it in GitHub Desktop.
Save mkrogh/1603268 to your computer and use it in GitHub Desktop.
rubyzip + open-uri (1.8.7 and 1.9.2)
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
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