From: Brian Candler Date: 2010-03-22T18:31:01+09:00 Subject: Re: Decompressing LZW compression from PDF file > Example of working LZW decompression in python is here: > http://pastebin.ca/1849009 > My translated code in ruby is here: http://pastebin.ca/1849012 Which version of ruby are you using? If it's 1.9 then your @fp[@inc] may fall foul of the character encoding rules. Try this in your initialize: puts @fp.encoding @fp.force_encoding("ASCII-8BIT") However if you pass in a StringIO rather than a String then you can just copy what python is doing: x = @fp.read(1) @buff = x[0].unpack("C").first and read(1) always reads single bytes. This has the advantage of being able to decompress directly from files, without reading them into RAM first. Minor suggestion: it might be more rubyish to return nil rather than raise EOFError, which would simplify your run loop to result = "" while code = readbits(@nbits) result << feed(code) end return result Regards, Brian. -- Posted via http://www.ruby-forum.com/.