From: Dominik Werder Date: 2003-05-17T23:06:34+09:00 Subject: Re: gzip cgi compression Here is the solution that works best for me. Unfortunately I had to introduce the class IOBuffer because the Zlib::GzipWriter can only write to IO objects. So I faked one by providing just the write method. Any other solution? Is there an IO compatible buffering class already? OK, heres the working code (GPL :) --- SNIP --- data = 'Thats a Good Thing (TM) @ ' << Time.new.to_s << '!' class IOBuffer def initialize @buf='' end def write s='' if s!=nil @buf << s s.length end end def buf @buf end end require 'zlib' buffer=IOBuffer.new z=Zlib::GzipWriter.new(buffer, 9) z.write data z.close zipped=buffer.buf puts 'HTTP/1.1 200 OK' puts 'Server: Ruby' puts 'Content-Encoding: gzip' puts 'Vary: Accept-Encoding' puts 'Transfer-Encoding: chunked' puts 'Content-Type: text/html' puts print zipped.length.to_s 16 print "\r\n" print zipped print "\r\n" print "0" print "\r\n\r\n"