Class: Async::HTTP::Body::ZStream

Inherits:
Wrapper show all
Defined in:
lib/async/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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Wrapper

#empty?, #finish, #read

Methods inherited from Readable

#each, #empty?, #finish, #join, #read

Constructor Details

#initialize(body, stream) ⇒ ZStream

Returns a new instance of ZStream.



49
50
51
52
53
54
55
56
# File 'lib/async/http/body/deflate.rb', line 49

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.



69
70
71
# File 'lib/async/http/body/deflate.rb', line 69

def input_length
  @input_length
end

#output_lengthObject (readonly)

Returns the value of attribute output_length.



70
71
72
# File 'lib/async/http/body/deflate.rb', line 70

def output_length
  @output_length
end

Class Method Details

.encoding_name(window_size) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/async/http/body/deflate.rb', line 39

def self.encoding_name(window_size)
	if window_size <= -8
		return 'deflate'
	elsif window_size >= 16
		return 'gzip'
	else
		return 'compress'
	end
end

Instance Method Details

#close(error = nil) ⇒ Object



58
59
60
61
62
# File 'lib/async/http/body/deflate.rb', line 58

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

#inspectObject



80
81
82
# File 'lib/async/http/body/deflate.rb', line 80

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

#lengthObject



64
65
66
67
# File 'lib/async/http/body/deflate.rb', line 64

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

#ratioObject



72
73
74
75
76
77
78
# File 'lib/async/http/body/deflate.rb', line 72

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