user27111987
user27111987

Reputation: 1085

Ruby - Get list of files from a binary stream which is a zip

I am making a HTTP Get request to my web server . My server returns a .zip file as octet-stream . I am collecting it as bits in a variable say 'X'

Question is how do I from the variable 'X' get the list of files and their contents within zip without saving the contents of variable 'X' on disk.

I want to do all this in Ruby. Is it possible.

Upvotes: 0

Views: 224

Answers (1)

jackiew
jackiew

Reputation: 21

If you are using the rubyzip gem, you can use Zip::InputStream, which accepts StringIO objects. Your HTTP response might already be a StringIO.

You could also use the Tempfile class from the standard library if the file-creating idiom is easier. These tempfiles are handled by the interpreter:

"When a Tempfile object is garbage collected, or when the Ruby interpreter exits, its associated temporary file is automatically deleted. This means that’s it’s unnecessary to explicitly delete a Tempfile after use..."

Upvotes: 2

Related Questions