class Protocol::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 body = message.body
		if remaining = body.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 finish

def finish
	if @body
		result = super
		
		@callback.call
		
		@body = nil
		
		return result
	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