Class: EventMachine::HttpDecoders::GZip

Inherits:
Base
  • Object
show all
Defined in:
lib/em-http/decoders.rb

Overview

Oneshot decompressor, due to lack of a streaming Gzip reader implementation. We may steal code from Zliby to improve this.

For now, do not put ‘gzip’ or ‘compressed’ in your accept-encoding header if you expect much data through the :on_response interface.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#<<, #finalize!, #initialize

Constructor Details

This class inherits a constructor from EventMachine::HttpDecoders::Base

Class Method Details

.encoding_namesObject



101
102
103
# File 'lib/em-http/decoders.rb', line 101

def self.encoding_names
  %w(gzip compressed)
end

Instance Method Details

#decompress(compressed) ⇒ Object



105
106
107
108
109
# File 'lib/em-http/decoders.rb', line 105

def decompress(compressed)
  @buf ||= ''
  @buf += compressed
  nil
end

#finalizeObject



111
112
113
114
115
116
117
# File 'lib/em-http/decoders.rb', line 111

def finalize
  begin
    Zlib::GzipReader.new(StringIO.new(@buf.to_s)).read
  rescue Zlib::Error
    raise DecoderError
  end
end