Class: Protocol::HTTP::Body::Deflate

Inherits:
ZStream show all
Defined in:
lib/protocol/http/body/deflate.rb

Constant Summary

Constants inherited from ZStream

ZStream::DEFAULT_LEVEL, ZStream::DEFLATE, ZStream::ENCODINGS, ZStream::GZIP

Instance Attribute Summary

Attributes inherited from ZStream

#input_length, #output_length

Attributes inherited from Wrapper

#body

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ZStream

#close, encoding_name, #initialize, #inspect, #length, #ratio

Methods inherited from Wrapper

#call, #close, #empty?, #finish, #initialize, #inspect, #length, #ready?, #stream?, wrap

Methods inherited from Readable

#call, #close, #each, #empty?, #finish, #join, #length, #ready?, #stream?

Constructor Details

This class inherits a constructor from Protocol::HTTP::Body::ZStream

Class Method Details

.for(body, window_size = GZIP, level = DEFAULT_LEVEL) ⇒ Object



88
89
90
# File 'lib/protocol/http/body/deflate.rb', line 88

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

Instance Method Details

#readObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/protocol/http/body/deflate.rb', line 92

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