Results 1 to 6 of 6

Thread: ruby gzip in web programming

  1. #1
    Join Date
    Dec 2009
    Posts
    211

    ruby gzip in web programming

    Hello guys,

    I was something confused if you all knows how to handle GZIP decompression in Ruby? I'm getting some content from the website encoded in GZIP and I need to deflate it. I already got sending and receiving/parsing data done, now I just want to know about the decoding procedure. I heard that Ruby came prepackaged with a copy of the ZLib library but I am unable to find the related documentation on it.

    Thanks and regards .
    Alisha.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Reading a gzipped file

    Zlib::GzipReader

    Zlib::GzipReader is on of the class through which you can read a gzipped file. GzipReader is necessary to collaborate with an IO, or -IO-lie, object.

    This is the implementation of the GzipReader below-

    Zlib::GzipReader.open('hoge.gz')
    {
    |gz|
    print gz.read
    }

    File.open('hoge.gz') do |f|
    gz = Zlib::GzipReader.new(f)
    print gz.read
    gz.close
    end

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Solution of "Invalid Header" issue

    Invalid Header in ruby programming -

    According to me this is the best way to split the header and content would be to do which would be as follows-

    Code:
    response = @tcp.gets(nil).split("\r\n\r\n")
    I will look more into this later. I am also not getting much documentation on how gzip streams are structured. The only thing I seemed to be able to find was this.

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Zlib::Error in web programming

    Zlib::Error

    This is the superclass for all occurred exceptions during the execution of Ruby/zlib.There are some exceptions which are defined as subclasses for Zlib::Error.These exceptions are raised when zlib library functions return with an error.

    The exceptions are as follows-

    • Zlib::streamEnd
    • Zlib::NeedDict
    • Zlib::dataError
    • Zlib::streamError
    • Zlib::MemError
    • Zlib::BufError
    • Zlib::VersionError

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    gzip a string in web programming

    I am going to show you an script which can help you to to compress the string. Compress and uncompressing of strings uses the deflate algorithm.

    In the following method of compression of a string,first the whole string is converted into the specified character set which would be necessary for programming languages where strings are represented as 2-byte/char Unicode.

    Code:
    require 'chilkat'
    
    gzip = Chilkat::CkGzip.new()
    
    
    success = gzip.UnlockComponent("Anything for 30-day trial")
    if (success != true)
        print gzip.lastErrorText() + "\n"
        exit
    end
    
    
    s = "A friend called me for surfing on the internet "
    s = s + " But I was too let to go with him..."
    s = s + s
    s = s + s
    
    cs = gzip.deflateStringENC(s,"windows-1252","base64")
    print cs + "\n";
    
    
    
    s2 = gzip.inflateStringENC(cs,"windows-1252","base64")
    print s2 + "\n";

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Compressing a string into a gzip file

    Compressing a string into a gzip file

    The GzipWriter would be used to compress the string and then can be transport to the file.This is one of the class for writing a gzipped file. GzipWriter should be used to associate with an instance of IO class.

    The code representation for the compressing a string into a gzip file would be as follows-

    Code:
    f = open('mine.gz', 'w')
    gz = GzipWriter.new(f)
    gz.write 'The reservation has been confirmed...'
    gz.close

Similar Threads

  1. Adobe Air needs HTTP gzip compression
    By Quinton in forum Windows Software
    Replies: 3
    Last Post: 01-07-2010, 05:10 PM
  2. Socket programming: Is any new Programming Language?
    By Kushan in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 11:13 AM
  3. How to use Ruby application and benefits of ruby application
    By FlayoFish in forum Windows Software
    Replies: 3
    Last Post: 30-07-2009, 11:17 AM
  4. Ruby - what is it
    By Cyclups in forum Software Development
    Replies: 10
    Last Post: 07-04-2009, 02:12 PM
  5. Replies: 3
    Last Post: 13-12-2008, 01:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,727,407,953.34212 seconds with 17 queries