Class: Falcon::Input

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

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Input

Returns a new instance of Input.



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

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

Instance Method Details

#closeObject



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

def close
	@body.finish
end

#each(&block) ⇒ Object



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

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

#eof?Boolean

Returns:

  • (Boolean)


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

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

#getsObject



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

def gets
	read
end

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



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

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



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

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