Object
Partial implementation of RFC 1952 to extract the deflate stream from a gzip file
# File lib/em-http/decoders.rb, line 124 def eof? @pos >= @data.size end
# File lib/em-http/decoders.rb, line 128 def extract_stream(compressed) @data << compressed pos = @pos while !eof? && !finished? buffer = "" case @state when :begin break if !read(10, buffer) if buffer.getbyte(0) != 0x1f || buffer.getbyte(1) != 0x8b raise DecoderError.new("magic header not found") end if buffer.getbyte(2) != 0x08 raise DecoderError.new("unknown compression method") end @flags = buffer.getbyte(3) if (@flags & 0xe0).nonzero? raise DecoderError.new("unknown header flags set") end # We don't care about these values, I'm leaving the code for reference # @time = buffer[4..7].unpack("V")[0] # little-endian uint32 # @extra_flags = buffer.getbyte(8) # @os = buffer.getbyte(9) @state = :extra_length when :extra_length if (@flags & 0x04).nonzero? break if !read(2, buffer) @extra_length = buffer.unpack("v")[0] # little-endian uint16 @state = :extra else @state = :extra end when :extra if (@flags & 0x04).nonzero? break if read(@extra_length, buffer) @state = :name else @state = :name end when :name if (@flags & 0x08).nonzero? while !(buffer = readbyte).nil? if buffer == 0 @state = :comment break end end else @state = :comment end when :comment if (@flags & 0x10).nonzero? while !(buffer = readbyte).nil? if buffer == 0 @state = :hcrc break end end else @state = :hcrc end when :hcrc if (@flags & 0x02).nonzero? break if !read(2, buffer) @state = :finish else @state = :finish end end end if finished? compressed[(@pos - pos)..-1] else "" end end
# File lib/em-http/decoders.rb, line 103 def finished? @state == :finish end
Generated with the Darkfish Rdoc Generator 2.