[Rubygems-developers] ZLib bites us again.

Jim Weirich jim.weirich at gmail.com
Sat Jun 23 13:55:55 EDT 2007

Sorry ... I'm catching up on some outstanding emails:

On Jun 20, 2007, at 8:34 AM, Daniel Berger wrote:
> Can you provide a link to Jamis' post? I must have missed it.

It was included as an attachment in the original message.  Perhaps  
the mailing list ate the attachment, so I will include it here directly:

From: Jamis Buck

Here's my work-around for the Zlib issue. Just replace the  
zipped_stream method in package.rb with the following:

     def zipped_stream(entry)
       entry.read(10) # skip the gzip header
       zis = Zlib::Inflate.new(-Zlib::MAX_WBITS)
       is = StringIO.new(zis.inflate(entry.read))
       zis.finish if zis

A slightly more robust gzip reader looks something like this (sorry  
about the magic numbers, it was just a proof of concept. if you want  
to use this more robust approach, let me know and I can do it up  
right with symbolic constants):

   require 'zlib'

   File.open("out.gz", "rb") do |f|
     head = f.read(10)

     abort "bad magic" if head[0] != 0x1f || head[1] != 0x8b
     abort "bad compression method #{head[2]}" if head[2] != 8
     abort "multipart gzip is unsupported" if head[3] & 0x2 != 0
     abort "encrypted gzip is unsupported" if head[3] & 0x20 != 0
     abort "unknown flags #{head[3]}" if head[3] & 0xc0 != 0

     if head[3] & 0x4 != 0
       len = f.read(2).unpack("n").first
       f.read(len + 2)

     if head[3] & 0x8 != 0
       loop { break if f.read(1) == 0 }

     if head[3] & 0x10 != 0
       loop { break if f.read(1) == 0 }

     zis = Zlib::Inflate.new(-Zlib::MAX_WBITS)
     result = zis.inflate(f.read)

     puts "got #{result.length} bytes"

- Jamis


-- Jim Weirich
-- jim at weirichhouse.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rubygems-developers/attachments/20070623/b097ec73/attachment-0001.html 

More information about the Rubygems-developers mailing list