Module | Zlib
In: | zlib/zlib.c

The Zlib module contains several classes for compressing and decompressing streams, and for working with "gzip" files.

## Classes

Following are the classes that are most likely to be of interest to the user: Zlib::Inflate Zlib::Deflate Zlib::GzipReader Zlib::GzipWriter

There are two important base classes for the classes above: Zlib::ZStream and Zlib::GzipFile. Everything else is an error class.

## Constants

Here’s a list.

      Zlib::VERSION
          The Ruby/zlib version string.

      Zlib::ZLIB_VERSION
          The string which represents the version of zlib.h.

      Zlib::BINARY
      Zlib::ASCII
      Zlib::UNKNOWN
          The integers representing data types which Zlib::ZStream#data_type
          method returns.

      Zlib::NO_COMPRESSION
      Zlib::BEST_SPEED
      Zlib::BEST_COMPRESSION
      Zlib::DEFAULT_COMPRESSION
          The integers representing compression levels which are an argument
          for Zlib::Deflate.new, Zlib::Deflate#deflate, and so on.

      Zlib::FILTERED
      Zlib::HUFFMAN_ONLY
      Zlib::DEFAULT_STRATEGY
          The integers representing compression methods which are an argument
          for Zlib::Deflate.new and Zlib::Deflate#params.

      Zlib::DEF_MEM_LEVEL
      Zlib::MAX_MEM_LEVEL
          The integers representing memory levels which are an argument for
          Zlib::Deflate.new, Zlib::Deflate#params, and so on.

      Zlib::MAX_WBITS
          The default value of windowBits which is an argument for
          Zlib::Deflate.new and Zlib::Inflate.new.

      Zlib::NO_FLUSH
      Zlib::SYNC_FLUSH
      Zlib::FULL_FLUSH
      Zlib::FINISH
          The integers to control the output of the deflate stream, which are
          an argument for Zlib::Deflate#deflate and so on.

      Zlib::OS_CODE
      Zlib::OS_MSDOS
      Zlib::OS_AMIGA
      Zlib::OS_VMS
      Zlib::OS_UNIX
      Zlib::OS_VMCMS
      Zlib::OS_ATARI
      Zlib::OS_OS2
      Zlib::OS_MACOS
      Zlib::OS_ZSYSTEM
      Zlib::OS_CPM
      Zlib::OS_TOPS20
      Zlib::OS_WIN32
      Zlib::OS_QDOS
      Zlib::OS_RISCOS
      Zlib::OS_UNKNOWN
          The return values of Zlib::GzipFile#os_code method.

### Methods

adler32 crc32 crc_table zlib_version

### Classes and Modules

Class Zlib::BufError
Class Zlib::DataError
Class Zlib::Deflate
Class Zlib::Error
Class Zlib::GzipFile
Class Zlib::GzipReader
Class Zlib::GzipWriter
Class Zlib::Inflate
Class Zlib::MemError
Class Zlib::NeedDict
Class Zlib::StreamEnd
Class Zlib::StreamError
Class Zlib::VersionError
Class Zlib::ZStream

### Public Instance methods

Zlib.adler32(string, adler)

Calculates Alder-32 checksum for `string`, and returns updated value of `adler`. If `string` is omitted, it returns the Adler-32 initial value. If `adler` is omitted, it assumes that the initial value is given to `adler`.

FIXME: expression.

[Source]

    /*
     * call-seq: Zlib.adler32(string, adler)
     *
     * Calculates Alder-32 checksum for +string+, and returns updated value of
     * +adler+. If +string+ is omitted, it returns the Adler-32 initial value. If
     * +adler+ is omitted, it assumes that the initial value is given to +adler+.
     *
     * FIXME: expression.
     */
    static VALUE
    rb_zlib_adler32(argc, argv, klass)
        int argc;
        VALUE *argv;
        VALUE klass;
    {
        return do_checksum(argc, argv, adler32);
    }

Zlib.crc32(string, adler)

Calculates CRC checksum for `string`, and returns updated value of `crc`. If `string` is omitted, it returns the CRC initial value. If `crc` is omitted, it assumes that the initial value is given to `crc`.

FIXME: expression.

[Source]

    /*
     * call-seq: Zlib.crc32(string, adler)
     *
     * Calculates CRC checksum for +string+, and returns updated value of +crc+. If
     * +string+ is omitted, it returns the CRC initial value. If +crc+ is omitted, it
     * assumes that the initial value is given to +crc+.
     *
     * FIXME: expression.
     */
    static VALUE
    rb_zlib_crc32(argc, argv, klass)
        int argc;
        VALUE *argv;
        VALUE klass;
    {
        return do_checksum(argc, argv, crc32);
    }

crc_table()

Returns the table for calculating CRC checksum as an array.

[Source]

    /*
     * Returns the table for calculating CRC checksum as an array.
     */
    static VALUE
    rb_zlib_crc_table(obj)
        VALUE obj;
    {
        const unsigned long *crctbl;
        VALUE dst;
        int i;

        crctbl = get_crc_table();
        dst = rb_ary_new2(256);

        for (i = 0; i < 256; i++) {
    	rb_ary_push(dst, rb_uint2inum(crctbl[i]));
        }
        return dst;
    }

zlib_version()

Returns the string which represents the version of zlib library.

[Source]

    /*
     * Returns the string which represents the version of zlib library.
     */
    static VALUE
    rb_zlib_version(klass)
        VALUE klass;
    {
        VALUE str;

        str = rb_str_new2(zlibVersion());
        OBJ_TAINT(str);  /* for safe */
        return str;
    }

[Validate]