Class: Protocol::HTTP::Body::ZStream

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

Direct Known Subclasses

Deflate, Inflate

Constant Summary collapse

DEFAULT_LEVEL =
7
DEFLATE =
-Zlib::MAX_WBITS
GZIP =
Zlib::MAX_WBITS | 16
ENCODINGS =
{
	'deflate' => DEFLATE,
	'gzip' => GZIP,
}

Instance Attribute Summary collapse

Attributes inherited from Wrapper

#body

Instance Method Summary collapse

Methods inherited from Wrapper

#call, #empty?, #finish, #read, #ready?, #stream?, wrap

Methods inherited from Readable

#call, #each, #empty?, #finish, #join, #read, #ready?, #stream?

Constructor Details

#initialize(body, stream) ⇒ ZStream

Returns a new instance of ZStream.



24
25
26
27
28
29
30
31
# File 'lib/protocol/http/body/deflate.rb', line 24

def initialize(body, stream)
	super(body)
	
	@stream = stream
	
	@input_length = 0
	@output_length = 0
end

Instance Attribute Details

#input_lengthObject (readonly)

Returns the value of attribute input_length.



44
45
46
# File 'lib/protocol/http/body/deflate.rb', line 44

def input_length
  @input_length
end

#output_lengthObject (readonly)

Returns the value of attribute output_length.



45
46
47
# File 'lib/protocol/http/body/deflate.rb', line 45

def output_length
  @output_length
end

Instance Method Details

#close(error = nil) ⇒ Object



33
34
35
36
37
# File 'lib/protocol/http/body/deflate.rb', line 33

def close(error = nil)
	@stream.close unless @stream.closed?
	
	super
end

#inspectObject



55
56
57
# File 'lib/protocol/http/body/deflate.rb', line 55

def inspect
	"#{super} | \#<#{self.class} #{(ratio*100).round(2)}%>"
end

#lengthObject



39
40
41
42
# File 'lib/protocol/http/body/deflate.rb', line 39

def length
	# We don't know the length of the output until after it's been compressed.
	nil
end

#ratioObject



47
48
49
50
51
52
53
# File 'lib/protocol/http/body/deflate.rb', line 47

def ratio
	if @input_length != 0
		@output_length.to_f / @input_length.to_f
	else
		1.0
	end
end