Zlib::GzipReader/Writer and strings

Discussion in 'Ruby' started by jim@freeze.org, Nov 22, 2004.

  1. Guest

    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
    , Nov 22, 2004
    #1
    1. Advertising

  2. On Mon, Nov 22, 2004 at 02:39:47PM +0900, 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.rubyarchive.org/
    Mauricio Fernández, Nov 22, 2004
    #2
    1. Advertising

  3. Guest

    * Mauricio Fernández <> [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
    , Nov 22, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henri
    Replies:
    1
    Views:
    375
    Henri
    Jul 13, 2004
  2. David G. Andersen

    Speed gap between zcat and zlib's GzipReader

    David G. Andersen, Oct 19, 2004, in forum: Ruby
    Replies:
    3
    Views:
    452
    Yukihiro Matsumoto
    Oct 26, 2004
  3. J-H Johansen

    Info regarding Zlib::GzipReader

    J-H Johansen, Jun 15, 2007, in forum: Ruby
    Replies:
    0
    Views:
    123
    J-H Johansen
    Jun 15, 2007
  4. Jos Backus
    Replies:
    10
    Views:
    490
    Jeremy Bopp
    Feb 4, 2011
  5. Thomas Wolf
    Replies:
    5
    Views:
    1,171
    Simon Krahnke
    Apr 26, 2012
Loading...

Share This Page