Skip to content

Support writing to IO #87

Open
Open
@fnordfish

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

data.concat buffer.get_bytes(0, length)

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

Metadata

Assignees

No one assigned

    Labels

    Status: UntriagedAn issue that has yet to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions