Open
Description
Let Archive::Writer.open_memory
support writing to an IO
or IO-like objects.
I have a web application that generation tar archives on the fly and streams them to the client.
Without that, we would either create a temp-file which needs to be cleaned up, or generate the entire archive in memory.
In
Instead of
concat
we could simply use <<
, which is both defined on String
and IO
and also by common streaming implementation like in sinatra (https://github.com/sinatra/sinatra/blob/main/examples/stream.ru)
Here's a quick test that seems to work for me.
def test_end_to_end_write_read_memory_stringio
memory = StringIO.new
Archive.write_open_memory(memory, Archive::COMPRESSION_GZIP, Archive::FORMAT_TAR) do |ar|
write_content ar
end
memory.rewind
verify_content_stream(memory)
end