In Files

  • zlib/zlib.c

Zlib

Constants

ASCII

Integer representing date types which Zlib::ZStream#data_type method returns

BEST_COMPRESSION

compression level 9

Which is an argument for Zlib::Deflate.new, Zlib::Deflate#deflate, and so on.

BEST_SPEED

compression level 1

Which is an argument for Zlib::Deflate.new, Zlib::Deflate#deflate, and so on.

BINARY

Integer representing date types which Zlib::ZStream#data_type method returns

DEFAULT_COMPRESSION

compression level -1

Which is an argument for Zlib::Deflate.new, Zlib::Deflate#deflate, and so on.

DEFAULT_STRATEGY

compression method 0

Which is an argument for Zlib::Deflate.new and Zlib::Deflate#params.

DEF_MEM_LEVEL

Default value is 8

The integer representing memory levels. Which are an argument for Zlib::Deflate.new, Zlib::Deflate#params, and so on.

FILTERED

compression method 1

Which is an argument for Zlib::Deflate.new and Zlib::Deflate#params.

FINISH

Oputput control - 4

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

FULL_FLUSH

Output control - 3

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

HUFFMAN_ONLY

compression method 2

Which is an argument for Zlib::Deflate.new and Zlib::Deflate#params.

MAX_MEM_LEVEL

Maximum level is 9

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

MAX_WBITS

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

NO_COMPRESSION

compression level 0

Which is an argument for Zlib::Deflate.new, Zlib::Deflate#deflate, and so on.

NO_FLUSH

Output control - 0

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

OS_AMIGA

From Zlib::GzipFile#os_code - 0x01

OS_ATARI

From Zlib::GzipFile#os_code - 0x05

OS_CODE

From Zlib::GzipFile#os_code - code of current host

OS_CPM

From Zlib::GzipFile#os_code - 0x09

OS_MACOS

From Zlib::GzipFile#os_code - 0x07

OS_MSDOS

From Zlib::GzipFile#os_code - 0x00

OS_OS2

From Zlib::GzipFile#os_code - 0x06

OS_QDOS

From Zlib::GzipFile#os_code - 0x0c

OS_RISCOS

From Zlib::GzipFile#os_code - 0x0d

OS_TOPS20

From Zlib::GzipFile#os_code - 0x0a

OS_UNIX

From Zlib::GzipFile#os_code - 0x03

OS_UNKNOWN

From Zlib::GzipFile#os_code - 0xff

OS_VMCMS

From Zlib::GzipFile#os_code - 0x04

OS_VMS

From Zlib::GzipFile#os_code - 0x02

OS_WIN32

From Zlib::GzipFile#os_code - 0x0b

OS_ZSYSTEM

From Zlib::GzipFile#os_code - 0x08

SYNC_FLUSH

Output control - 2

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

UNKNOWN

Integer representing date types which Zlib::ZStream#data_type method returns

VERSION

The Ruby/zlib version string.

ZLIB_VERSION

The string which represents the version of zlib.h

Public Class Methods

adler32(string, adler) click to toggle source

Calculates Adler-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(int argc, VALUE *argv, VALUE klass)
{
    return do_checksum(argc, argv, adler32);
}
            
adler32_combine(adler1, adler2, len2) click to toggle source

Combine two Adler-32 check values in to one. alder1 is the first Adler-32 value, adler2 is the second Adler-32 value. len2 is the length of the string used to generate adler2.

 
               static VALUE
rb_zlib_adler32_combine(VALUE klass, VALUE adler1, VALUE adler2, VALUE len2)
{
  return ULONG2NUM(
        adler32_combine(NUM2ULONG(adler1), NUM2ULONG(adler2), NUM2LONG(len2)));
}
            
crc32(string, adler) click to toggle source

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(int argc, VALUE *argv, VALUE klass)
{
    return do_checksum(argc, argv, crc32);
}
            
crc32_combine(crc1, crc2, len2) click to toggle source

Combine two CRC-32 check values in to one. crc1 is the first CRC-32 value, crc2 is the second CRC-32 value. len2 is the length of the string used to generate crc2.

 
               static VALUE
rb_zlib_crc32_combine(VALUE klass, VALUE crc1, VALUE crc2, VALUE len2)
{
  return ULONG2NUM(
        crc32_combine(NUM2ULONG(crc1), NUM2ULONG(crc2), NUM2LONG(len2)));
}
            
crc_table() click to toggle source

Returns the table for calculating CRC checksum as an array.

 
               static VALUE
rb_zlib_crc_table(VALUE obj)
{
#if !defined(HAVE_TYPE_Z_CRC_T)
    /* z_crc_t is defined since zlib-1.2.7. */
    typedef unsigned long z_crc_t;
#endif
    const z_crc_t *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;
}
            
deflate(string[, level]) click to toggle source
Zlib::Deflate.deflate(string[, level])

Compresses the given string. Valid values of level are NO_COMPRESSION, BEST_SPEED, BEST_COMPRESSION, DEFAULT_COMPRESSION, and an integer from 0 to 9 (the default is 6).

This method is almost equivalent to the following code:

def deflate(string, level)
  z = Zlib::Deflate.new(level)
  dst = z.deflate(string, Zlib::NO_FLUSH)
  z.close
  dst
end

See also ::inflate

 
               static VALUE
rb_deflate_s_deflate(int argc, VALUE *argv, VALUE klass)
{
    struct zstream z;
    VALUE src, level, dst, args[2];
    int err, lev;

    rb_scan_args(argc, argv, "11", &src, &level);

    lev = ARG_LEVEL(level);
    StringValue(src);
    zstream_init_deflate(&z);
    err = deflateInit(&z.stream, lev);
    if (err != Z_OK) {
        raise_zlib_error(err, z.stream.msg);
    }
    ZSTREAM_READY(&z);

    args[0] = (VALUE)&z;
    args[1] = src;
    dst = rb_ensure(deflate_run, (VALUE)args, zstream_end, (VALUE)&z);

    OBJ_INFECT(dst, src);
    return dst;
}
            
Zlib::Inflate.inflate(string) click to toggle source

Decompresses string. Raises a Zlib::NeedDict exception if a preset dictionary is needed for decompression.

This method is almost equivalent to the following code:

def inflate(string)
  zstream = Zlib::Inflate.new
  buf = zstream.inflate(string)
  zstream.finish
  zstream.close
  buf
end

See also ::deflate

 
               static VALUE
rb_inflate_s_inflate(VALUE obj, VALUE src)
{
    struct zstream z;
    VALUE dst, args[2];
    int err;

    StringValue(src);
    zstream_init_inflate(&z);
    err = inflateInit(&z.stream);
    if (err != Z_OK) {
        raise_zlib_error(err, z.stream.msg);
    }
    ZSTREAM_READY(&z);

    args[0] = (VALUE)&z;
    args[1] = src;
    dst = rb_ensure(inflate_run, (VALUE)args, zstream_end, (VALUE)&z);

    OBJ_INFECT(dst, src);
    return dst;
}
            
zlib_version() click to toggle source

Returns the string which represents the version of zlib library.

 
               static VALUE
rb_zlib_version(VALUE klass)
{
    VALUE str;

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

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus