Class: Protocol::HTTP1::Body::Remainder

Inherits:
HTTP::Body::Readable
  • Object
show all
Defined in:
lib/protocol/http1/body/remainder.rb

Constant Summary collapse

BLOCK_SIZE =
1024 * 64

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Remainder

block_size may be removed in the future. It is better managed by stream.



30
31
32
# File 'lib/protocol/http1/body/remainder.rb', line 30

def initialize(stream)
	@stream = stream
end

Instance Method Details

#call(stream) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/protocol/http1/body/remainder.rb', line 52

def call(stream)
	self.each do |chunk|
		stream.write(chunk)
	end
	
	stream.flush
end

#close(error = nil) ⇒ Object



38
39
40
41
42
43
# File 'lib/protocol/http1/body/remainder.rb', line 38

def close(error = nil)
	# We can't really do anything in this case except close the connection.
	@stream.close
	
	super
end

#empty?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/protocol/http1/body/remainder.rb', line 34

def empty?
	@stream.eof? or @stream.closed?
end

#inspectObject



64
65
66
# File 'lib/protocol/http1/body/remainder.rb', line 64

def inspect
	"\#<#{self.class} #{@stream.closed? ? 'closed' : 'open'}>"
end

#joinObject



60
61
62
# File 'lib/protocol/http1/body/remainder.rb', line 60

def join
	@stream.read
end

#readObject

TODO this is a bit less efficient in order to maintain compatibility with ‘IO`.



46
47
48
49
50
# File 'lib/protocol/http1/body/remainder.rb', line 46

def read
	@stream.readpartial(BLOCK_SIZE)
rescue EOFError
	return nil
end