class Falcon::Input

def close

def close
	@body.close
end

def each(&block)

def each(&block)
	while @index < @chunks.count
		chunk = @chunks[@index]
		@index += 1
		yield chunk
	end
	
	@body.each do |chunk|
		@chunks << chunk
		yield chunk
	end
	
	@closed = true
end

def eof?

def eof?
	@closed and @buffer.nil?
end

def gets

def gets
	read
end

def initialize(body)

def initialize(body)
	@body = body
	@chunks = []
	
	@buffer = nil
	@closed = false
end

def read(length = nil, buffer = nil)

def read(length = nil, buffer = nil)
	unless @buffer
		self.each do |chunk|
			@buffer = chunk
			break
		end
	end
	
	if @buffer
		if length and @buffer.bytesize < length
			return @buffer.slice!(0, length)
		else
			buffer = @buffer
			@buffer = nil
			return buffer
		end
	end
end

def rewind

def rewind
	@index = 0
	@closed = false
end