Zlib::GzipReader/Writer and strings

Hi

Is there a way for Zlib::GzipReader or GzipWriter
to read and write to a string as a StringIO object?

I have tried and am not having any luck.

I am using Ruby 1.8.1.

Thanks

···

--
Jim Freeze
Code Red. Code Ruby

Hi

Is there a way for Zlib::GzipReader or GzipWriter
to read and write to a string as a StringIO object?

I have tried and am not having any luck.

I am using Ruby 1.8.1.

Just doing Zlib::GzipReader.new(anIO) (where anIO responds to #read
with the same semantics as IO) works for me.

require 'stringio'; require 'zlib'

=> true

a = StringIO.new ""

=> #<StringIO:0x40201c14>

b = Zlib::GzipWriter.new a; b.write("foo"*10); b.finish; a.string

=> "\037\213\010\000\363\256\241A\000\003K\313\317O\303\215\000\365*\235\350\036\000\000\000"

a.rewind; c = Zlib::GzipReader.new(a); c.read

=> "foofoofoofoofoofoofoofoofoofoo"

···

On Mon, Nov 22, 2004 at 02:39:47PM +0900, jim@freeze.org wrote:

--
Hassle-free packages for Ruby?
RPA is available from http://www.rubyarchive.org/

* Mauricio Fernández <batsman.geo@yahoo.com> [2004-11-22 18:21:07 +0900]:

Just doing Zlib::GzipReader.new(anIO) (where anIO responds to #read
with the same semantics as IO) works for me.

>> require 'stringio'; require 'zlib'
=> true
>> a = StringIO.new ""
=> #<StringIO:0x40201c14>
>> b = Zlib::GzipWriter.new a; b.write("foo"*10); b.finish; a.string

Thanks. I think I was missing the b.finish statement.

···

--
Jim Freeze
Code Red. Code Ruby