From: Ned Konz Date: 2001-10-05T06:34:57+09:00 Subject: [ruby-talk:22102] Re: gzip a string On Thursday 04 October 2001 02:02 pm, Tobias Reif wrote: > Hi, > > how to gzip a string? Just to compress it, or to make a gzip file (which has a header, of course, that the compressed string itself wouldn't)? Use ruby/zlib http://www.blue.sky.or.jp/ To compress a string (but not to make it a gzip file): #!/usr/local/bin/ruby require 'zlib' defl = Deflate.new $stdout.print defl.deflate("abcdef\n"); $stdout.print defl.deflate(nil); To compress a string into a gzip file, use GzipWriter (from the docs): The class for writing a gzipped file. GzipWriter should be used to associate with an instance of IO class (or an object which has the same methods as IO has). f = open('hoge.gz', 'w') gz = GzipWriter.new(f) gz.write 'jugemu jugemu gokou no surikire...' gz.close -- Ned Konz currently: Stanwood, WA email: ned@bike-nomad.com homepage: http://bike-nomad.com