Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Zlib::GzipReader/Writer and strings

Reply
Thread Tools

Zlib::GzipReader/Writer and strings

 
 
jim@freeze.org
Guest
Posts: n/a
 
      11-22-2004
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


 
Reply With Quote
 
 
 
 
Mauricio Fernández
Guest
Posts: n/a
 
      11-22-2004
On Mon, Nov 22, 2004 at 02:39:47PM +0900, http://www.velocityreviews.com/forums/(E-Mail Removed) 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\3 03\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.rubyarchive.org/


 
Reply With Quote
 
 
 
 
jim@freeze.org
Guest
Posts: n/a
 
      11-22-2004
* Mauricio Fernández <(E-Mail Removed)> [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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
How to generate k+1 length strings from a list of k length strings? Girish Sahani Python 17 06-09-2006 11:01 AM
Catching std::strings and c-style strings at once Kurt Krueckeberg C++ 2 11-17-2004 03:53 AM
convert list of strings to set of regexes; convert list of strings to trie Klaus Neuner Python 7 07-26-2004 07:25 AM
Comparing strings from within strings Rick C Programming 3 10-21-2003 09:10 AM



Advertisments