class Async::HTTP::DeflateBody

def self.for(body, encoding = GZIP, level = Zlib::DEFAULT_COMPRESSION)

def self.for(body, encoding = GZIP, level = Zlib::DEFAULT_COMPRESSION)
	self.new(body, Zlib::Deflate.new(level, encoding))
end

def self.for_request(headers, body, *args)

def self.for_request(headers, body, *args)
	if content_encoding = headers['content-encoding']
		if encoding = ENCODINGS[content_encoding]
			return self.for(body, encoding, *args)
		end
	end
	
	return body
end

def close

def close
	@body = @body.close
	
	return self
end

def each(&block)

def each(&block)
	return to_enum unless block_given?
	
	while chunk = self.read
		yield chunk
	end
end

def finished?

def finished?
	@body.finished?
end

def initialize(body, stream)

def initialize(body, stream)
	@body = body
	@stream = stream
end

def join

def join
	buffer = Async::IO::BinaryString.new
	
	while chunk = self.read
		buffer << chunk
	end
	
	return buffer
end

def read

def read
	return if @stream.finished?
	
	if chunk = @body.read
		return @stream.deflate(chunk, Zlib::SYNC_FLUSH)
	else
		chunk = @stream.finish
		
		return chunk.empty? ? nil : chunk
	end
end