Class: Wash::Streamer

Inherits:
Object
  • Object
show all
Defined in:
lib/wash/streamer.rb

Overview

Streamer is a class meant to be used by implementations of Wash::Entry#stream.

Instance Method Summary collapse

Constructor Details

#initializeStreamer

Returns a new instance of Streamer.



6
7
8
# File 'lib/wash/streamer.rb', line 6

def initialize
  @first_chunk = true
end

Instance Method Details

#write(chunk) ⇒ Object

write writes the given chunk to STDOUT then flushes it to ensure that Wash receives the data. If the chunk is the first chunk that’s written, then write will print the “200” header prior to writing the chunk.

Parameters:

  • chunk

    The chunk to be written



15
16
17
18
19
20
21
22
# File 'lib/wash/streamer.rb', line 15

def write(chunk)
    if @first_chunk
      puts("200")
      @first_chunk = false
    end
    $stdout.print(chunk)
    $stdout.flush
end