Skip to content

Instantly share code, notes, and snippets.

@escowles
Last active August 29, 2015 13:57
Show Gist options
  • Save escowles/9371063 to your computer and use it in GitHub Desktop.
Save escowles/9371063 to your computer and use it in GitHub Desktop.
list and extract entries from a zip file over http
source 'https://rubygems.org'
gem 'zipruby'
#!/usr/bin/env ruby
# extract a file from a zip archive
require 'net/http'
require 'zipruby'
uri = URI( 'http://localhost/tmp/tmp.zip' )
Net::HTTP.start( uri.host, uri.port ) do |http|
req = Net::HTTP::Get.new uri
res = http.request req
Zip::Archive.open_buffer(res.read_body) do |zip|
zip.fopen( '2.txt' ) do |f|
while chunk = f.read( 8192 )
print chunk
end
end
end
end
#!/usr/bin/env ruby
# list files in a zip archive
require 'zipruby'
uri = URI( 'http://localhost/tmp/tmp.zip' )
Net::HTTP.start( uri.host, uri.port ) do |http|
req = Net::HTTP::Get.new uri
res = http.request req
Zip::Archive.open_buffer(res.read_body) do |zip|
zip.each do |f|
puts "#{f.name} (#{f.size})"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment