class Async::HTTP::Body::Streamable

Invokes a callback once the body has finished reading.

def self.wrap(message, &block)

def self.wrap(message, &block)
	if message and message.body
		if remaining = message.headers['content-length']
			remaining = Integer(remaining)
		end
		
		message.body = self.new(message.body, block, remaining)
	else
		yield
	end
end

def close(*)

def close(*)
	if @body
		super
		
		@callback.call
		
		@body = nil
	end
end

def initialize(body, callback, remaining = nil)

def initialize(body, callback, remaining = nil)
	super(body)
	
	@callback = callback
	@remaining = remaining
end

def read

def read
	if chunk = super
		@remaining -= chunk.bytesize if @remaining
	else
		if @remaining and @remaining > 0
			raise EOFError, "Expected #{@remaining} more bytes!"
		end
	end
	
	return chunk
end