Class: HTTP::Response::Inflater

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

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"

Parameters:

  • size (Integer)
  • outbuf (String, nil)

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

#zstreamZlib::Inflate

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the zlib inflate stream

Returns:

  • (Zlib::Inflate)


55
56
57
# File 'lib/http/response/inflater.rb', line 55

def zstream
  @zstream ||= Zlib::Inflate.new(32 + Zlib::MAX_WBITS)
end