Reputation: 1085
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
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