[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Zlib::GzipReader/Writer and strings

Jim Freeze

11/22/2004 5:40:00 AM

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


2 Answers

Mauricio Fernández

11/22/2004 9:21:00 AM

0

On Mon, Nov 22, 2004 at 02:39:47PM +0900, jim@freeze.org wrote:
> 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"


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


Jim Freeze

11/22/2004 8:42:00 PM

0

* 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