class Async::HTTP::Body::Deflate

def self.for(body, window_size = GZIP, level = DEFAULT_LEVEL)

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

def read

def read
	return if @stream.finished?
	
	# The stream might have been closed while waiting for the chunk to come in.
	if chunk = super
		@input_length += chunk.bytesize
		
		chunk = @stream.deflate(chunk, Zlib::SYNC_FLUSH)
		
		@output_length += chunk.bytesize
		
		return chunk
	elsif !@stream.closed?
		chunk = @stream.finish
		
		@output_length += chunk.bytesize
		
		return chunk.empty? ? nil : chunk
	end
end