Class: EventMachine::HttpDecoders::GZip

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

Defined Under Namespace

Classes: LazyStringIO

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



95
96
97
# File 'lib/em-http/decoders.rb', line 95

def self.encoding_names
  %w(gzip compressed)
end

Instance Method Details

#decompress(compressed) ⇒ Object



99
100
101
102
103
104
105
106
107
108
# File 'lib/em-http/decoders.rb', line 99

def decompress(compressed)
  @buf ||= LazyStringIO.new
  @buf << compressed

  # Zlib::GzipReader loads input in 2048 byte chunks
  if @buf.size > 2048
    @gzip ||= Zlib::GzipReader.new @buf
    @gzip.readline
  end
end

#finalizeObject



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

def finalize
  begin
    @gzip ||= Zlib::GzipReader.new @buf
    @gzip.read
  rescue Zlib::Error
    raise DecoderError
  end
end