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, #initialize, #inspect, #length, #ratio

Methods inherited from Wrapper

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

Methods inherited from Readable

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

Constructor Details

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

Class Method Details

.for(body, encoding = GZIP) ⇒ Object



14
15
16
# File 'lib/protocol/http/body/inflate.rb', line 14

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

Instance Method Details

#readObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/protocol/http/body/inflate.rb', line 22

def read
	return if @stream.finished?
	
	# The stream might have been closed while waiting for the chunk to come in.
	while chunk = super
		@input_length += chunk.bytesize
		
		# It's possible this triggers the stream to finish.
		chunk = @stream.inflate(chunk)
		
		break unless chunk&.empty?
	end
	
	if 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

#stream?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/protocol/http/body/inflate.rb', line 18

def stream?
	false
end