Class: Protocol::HTTP1::Body::Fixed

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream, length) ⇒ Fixed

Returns a new instance of Fixed.



29
30
31
32
33
# File 'lib/protocol/http1/body/fixed.rb', line 29

def initialize(stream, length)
	@stream = stream
	@length = length
	@remaining = length
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



35
36
37
# File 'lib/protocol/http1/body/fixed.rb', line 35

def length
  @length
end

#remainingObject (readonly)

Returns the value of attribute remaining.



36
37
38
# File 'lib/protocol/http1/body/fixed.rb', line 36

def remaining
  @remaining
end

Instance Method Details

#close(error = nil) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/protocol/http1/body/fixed.rb', line 42

def close(error = nil)
	if @remaining != 0
		@stream.close
	end
	
	super
end

#empty?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/protocol/http1/body/fixed.rb', line 38

def empty?
	@remaining == 0
end

#inspectObject



70
71
72
# File 'lib/protocol/http1/body/fixed.rb', line 70

def inspect
	"\#<#{self.class} length=#{@length} remaining=#{@remaining}>"
end

#joinObject



62
63
64
65
66
67
68
# File 'lib/protocol/http1/body/fixed.rb', line 62

def join
	buffer = @stream.read(@remaining)
	
	@remaining = 0
	
	return buffer
end

#readObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/protocol/http1/body/fixed.rb', line 50

def read
	if @remaining > 0
		if chunk = @stream.readpartial(@remaining)
			@remaining -= chunk.bytesize
			
			return chunk
		else
			raise EOFError, "Stream closed with #{@remaining} bytes remaining!"
		end
	end
end