Class: TxghServer::TgzStreamResponse

Inherits:
StreamResponse show all
Defined in:
lib/txgh-server/tgz_stream_response.rb

Constant Summary collapse

PERMISSIONS =
0644

Instance Attribute Summary

Attributes inherited from StreamResponse

#attachment, #enum

Instance Method Summary collapse

Methods inherited from StreamResponse

#error, #headers, #initialize, #streaming?

Constructor Details

This class inherits a constructor from TxghServer::StreamResponse

Instance Method Details

#file_extensionObject



27
28
29
# File 'lib/txgh-server/tgz_stream_response.rb', line 27

def file_extension
  '.tgz'
end

#write_to(stream) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/txgh-server/tgz_stream_response.rb', line 9

def write_to(stream)
  Zlib::GzipWriter.wrap(stream) do |gz|
    pipe = StringIO.new('', 'wb')
    tar = Gem::Package::TarWriter.new(pipe)

    enum.each do |file_name, contents|
      tar.add_file(file_name, PERMISSIONS) do |f|
        f.write(contents)
      end

      flush(tar, pipe, gz)
      stream.flush
    end

    flush(tar, pipe, gz)
  end
end