Class: Daps::Server::ArchiveStreamer

Inherits:
Cramp::Controller::Action
  • Object
show all
Defined in:
lib/daps/server.rb

Constant Summary collapse

@@activated =
false

Instance Method Summary collapse

Instance Method Details

#open_streamObject



45
46
47
48
# File 'lib/daps/server.rb', line 45

def open_stream
  puts "Transferring archive..."
  @pipe = EM.popen('tar -czf - .', Daps::Server::Pipe, self)
end

#render(data) ⇒ Object



59
60
61
62
63
# File 'lib/daps/server.rb', line 59

def render(data)
  term = "\r\n"
  size = Rack::Utils.bytesize(data)
  super([size.to_s(16), term, data, term].join)
end

#respond_withObject



41
42
43
# File 'lib/daps/server.rb', line 41

def respond_with
  [200, {'Content-Type' => 'application/x-gzip', 'Transfer-Encoding' => 'chunked'}]
end

#terminateObject



50
51
52
53
54
55
56
57
# File 'lib/daps/server.rb', line 50

def terminate
  @pipe.terminate if @pipe
  EM.next_tick {
    if @env['daps.token'] == @token
      EM.stop_event_loop
    end
  }
end

#verify_tokenObject



31
32
33
34
35
36
37
38
39
# File 'lib/daps/server.rb', line 31

def verify_token
  @token = File.basename(@env['PATH_INFO'])
  if @env['daps.token'] != @token or @@activated
    halt 403, {'Content-Type' => 'text/html'}, 'back off!!'
  else
    @@activated = true
    yield
  end
end