Class: Protocol::HTTP::Body::Inflate

Inherits:
ZStream show all
Defined in:
lib/protocol/http/body/inflate.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, encoding = GZIP) ⇒ Object



31
32
33
# File 'lib/protocol/http/body/inflate.rb', line 31

def self.for(body, encoding = GZIP)
	self.new(body, Zlib::Inflate.new(encoding))
end

Instance Method Details

#readObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/protocol/http/body/inflate.rb', line 35

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
		
		# It's possible this triggers the stream to finish.
		chunk = @stream.inflate(chunk)
		
		@output_length += chunk.bytesize
	elsif !@stream.closed?
		chunk = @stream.finish
		
		@output_length += chunk.bytesize
	end
	
	if chunk.empty? and @stream.finished?
		return nil
	end
	
	return chunk
end