Class: Falcon::Adapters::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/falcon/adapters/input.rb

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Input

Returns a new instance of Input.



26
27
28
29
30
31
32
33
# File 'lib/falcon/adapters/input.rb', line 26

def initialize(body)
	@body = body
	@chunks = []
	
	@index = 0
	@buffer = Async::IO::BinaryString.new
	@finished = false
end

Instance Method Details

#closeObject



78
79
80
# File 'lib/falcon/adapters/input.rb', line 78

def close
	@body.finish
end

#each(&block) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/falcon/adapters/input.rb', line 35

def each(&block)
	return to_enum unless block_given?
	
	while chunk = read_next
		yield chunk
	end
	
	@closed = true
end

#eof?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/falcon/adapters/input.rb', line 70

def eof?
	@finished and @buffer.empty?
end

#getsObject



74
75
76
# File 'lib/falcon/adapters/input.rb', line 74

def gets
	read
end

#read(length = nil, buffer = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/falcon/adapters/input.rb', line 51

def read(length = nil, buffer = nil)
	if length
		fill_buffer(length) if @buffer.bytesize <= length
		
		return @buffer.slice!(0, length)
	else
		buffer ||= Async::IO::BinaryString.new
		
		buffer << @buffer
		@buffer.clear
		
		while chunk = read_next
			buffer << chunk
		end
		
		return buffer
	end
end

#rewindObject



45
46
47
48
49
# File 'lib/falcon/adapters/input.rb', line 45

def rewind
	@index = 0
	@finished = false
	@buffer.clear
end