Class: HTTP::Response::Inflater

Inherits:
Object
  • Object
show all
Defined in:
lib/http/response/inflater.rb

Overview

Decompresses gzip/deflate response body streams

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Inflater

Create a new Inflater wrapping a connection

Examples:

Inflater.new(connection)

Parameters:



26
27
28
# File 'lib/http/response/inflater.rb', line 26

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionHTTP::Connection (readonly)

The underlying connection

Examples:

inflater.connection

Returns:



16
17
18
# File 'lib/http/response/inflater.rb', line 16

def connection
  @connection
end

Instance Method Details

#readpartialString

Read and inflate a chunk of the response body

Examples:

inflater.readpartial # => "decompressed data"

Returns:

  • (String)

Raises:

  • (EOFError)

    when no more data left



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/http/response/inflater.rb', line 38

def readpartial(*)
  chunk = @connection.readpartial(*)
  zstream.inflate(chunk)
rescue EOFError
  unless zstream.closed?
    zstream.finished? ? zstream.finish : zstream.reset
    zstream.close
  end

  raise
end