Type:
Module
Constants:
VERSION : rb_str_new2(RUBY_ZLIB_VERSION)

The Ruby/zlib version string.

ZLIB_VERSION : rb_str_new2(ZLIB_VERSION)

The string which represents the version of zlib.h

BINARY : INT2FIX(Z_BINARY)

Represents binary data as guessed by deflate.

See Zlib::ZStream#data_type.

ASCII : INT2FIX(Z_ASCII)

Represents text data as guessed by deflate.

NOTE: The underlying constant Z_ASCII was deprecated in favor of Z_TEXT in zlib 1.2.2. New applications should not use this constant.

See Zlib::ZStream#data_type.

TEXT : INT2FIX(Z_TEXT)

Represents text data as guessed by deflate.

See Zlib::ZStream#data_type.

UNKNOWN : INT2FIX(Z_UNKNOWN)

Represents an unknown data type as guessed by deflate.

See Zlib::ZStream#data_type.

NO_COMPRESSION : INT2FIX(Z_NO_COMPRESSION)

No compression, passes through data untouched. Use this for appending pre-compressed data to a deflate stream.

BEST_SPEED : INT2FIX(Z_BEST_SPEED)

Fastest compression level, but with with lowest space savings.

BEST_COMPRESSION : INT2FIX(Z_BEST_COMPRESSION)

Slowest compression level, but with the best space savings.

DEFAULT_COMPRESSION : INT2FIX(Z_DEFAULT_COMPRESSION)

Default compression level which is a good trade-off between space and time

FILTERED : INT2FIX(Z_FILTERED)

Deflate strategy for data produced by a filter (or predictor). The effect of FILTERED is to force more Huffman codes and less string matching; it is somewhat intermediate between DEFAULT_STRATEGY and HUFFMAN_ONLY. Filtered data consists mostly of small values with a somewhat random distribution.

HUFFMAN_ONLY : INT2FIX(Z_HUFFMAN_ONLY)

Deflate strategy which uses Huffman codes only (no string matching).

RLE : INT2FIX(Z_RLE)

Deflate compression strategy designed to be almost as fast as HUFFMAN_ONLY, but give better compression for PNG image data.

FIXED : INT2FIX(Z_FIXED)

Deflate strategy which prevents the use of dynamic Huffman codes, allowing for a simpler decoder for specialized applications.

DEFAULT_STRATEGY : INT2FIX(Z_DEFAULT_STRATEGY)

Default deflate strategy which is used for normal data.

MAX_WBITS : INT2FIX(MAX_WBITS)

The maximum size of the zlib history buffer. Note that zlib allows larger values to enable different inflate modes. See Zlib::Inflate.new for details.

DEF_MEM_LEVEL : INT2FIX(DEF_MEM_LEVEL)

The default memory level for allocating zlib deflate compression state.

MAX_MEM_LEVEL : INT2FIX(MAX_MEM_LEVEL)

The maximum memory level for allocating zlib deflate compression state.

NO_FLUSH : INT2FIX(Z_NO_FLUSH)

NO_FLUSH is the default flush method and allows deflate to decide how much data to accumulate before producing output in order to maximize compression.

SYNC_FLUSH : INT2FIX(Z_SYNC_FLUSH)

The SYNC_FLUSH method flushes all pending output to the output buffer and the output is aligned on a byte boundary. Flushing may degrade compression so it should be used only when necessary, such as at a request or response boundary for a network stream.

FULL_FLUSH : INT2FIX(Z_FULL_FLUSH)

Flushes all output as with SYNC_FLUSH, and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if random access is desired. Like SYNC_FLUSH, using FULL_FLUSH too often can seriously degrade compression.

FINISH : INT2FIX(Z_FINISH)

Processes all pending input and flushes pending output.

OS_CODE : INT2FIX(OS_CODE)

The OS code of current host

OS_MSDOS : INT2FIX(OS_MSDOS)

OS code for MSDOS hosts

OS_AMIGA : INT2FIX(OS_AMIGA)

OS code for Amiga hosts

OS_VMS : INT2FIX(OS_VMS)

OS code for VMS hosts

OS_UNIX : INT2FIX(OS_UNIX)

OS code for UNIX hosts

OS_ATARI : INT2FIX(OS_ATARI)

OS code for Atari hosts

OS_OS2 : INT2FIX(OS_OS2)

OS code for OS2 hosts

OS_MACOS : INT2FIX(OS_MACOS)

OS code for Mac OS hosts

OS_TOPS20 : INT2FIX(OS_TOPS20)

OS code for TOPS-20 hosts

OS_WIN32 : INT2FIX(OS_WIN32)

OS code for Win32 hosts

OS_VMCMS : INT2FIX(OS_VMCMS)

OS code for VM OS hosts

OS_ZSYSTEM : INT2FIX(OS_ZSYSTEM)

OS code for Z-System hosts

OS_CPM : INT2FIX(OS_CPM)

OS code for CP/M hosts

OS_QDOS : INT2FIX(OS_QDOS)

OS code for QDOS hosts

OS_RISCOS : INT2FIX(OS_RISCOS)

OS code for RISC OS hosts

OS_UNKNOWN : INT2FIX(OS_UNKNOWN)

OS code for unknown hosts

This module provides access to the zlib library. Zlib is designed to be a portable, free, general-purpose, legally unencumbered – that is, not covered by any patents – lossless data-compression library for use on virtually any computer hardware and operating system.

The zlib compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data.

The zlib compressed data format is described in RFC 1950, which is a wrapper around a deflate stream which is described in RFC 1951.

The library also supports reading and writing files in gzip (.gz) format with an interface similar to that of IO. The gzip format is described in RFC 1952 which is also a wrapper around a deflate stream.

The zlib format was designed to be compact and fast for use in memory and on communications channels. The gzip format was designed for single-file compression on file systems, has a larger header than zlib to maintain directory information, and uses a different, slower check method than zlib.

See your system's zlib.h for further information about zlib

Sample usage

Using the wrapper to compress strings with default parameters is quite simple:

require "zlib"

data_to_compress = File.read("don_quixote.txt")

puts "Input size: #{data_to_compress.size}"
#=> Input size: 2347740

data_compressed = Zlib::Deflate.deflate(data_to_compress)

puts "Compressed size: #{data_compressed.size}"
#=> Compressed size: 887238

uncompressed_data = Zlib::Inflate.inflate(data_compressed)

puts "Uncompressed data is: #{uncompressed_data}"
#=> Uncompressed data is: The Project Gutenberg EBook of Don Quixote...

Class tree

(if you have GZIP_SUPPORT)

adler32

Zlib.adler32(string, adler) Class Public methods Calculates Adler-32 checksum

2015-06-14 22:44:44
crc32

Zlib.crc32(string, crc) Class Public methods Calculates CRC checksum for string

2015-06-14 22:51:50
inflate

Zlib.inflate(string)Zlib::Inflate.inflate(string) Class Public methods Decompresses

2015-06-14 23:08:49
adler32_combine

Zlib.adler32_combine(adler1, adler2, len2) Class Public methods Combine two

2015-06-14 22:49:05
zlib_version

zlib_version() Class Public methods Returns the string which represents the

2015-06-14 23:10:24
crc32_combine

Zlib.crc32_combine(crc1, crc2, len2) Class Public methods Combine two CRC-32

2015-06-14 22:55:56
crc_table

crc_table() Class Public methods Returns the table for calculating CRC checksum

2015-06-14 22:59:34
deflate

Zlib.deflate(string[, level])Zlib::Deflate.deflate(string[, level]) Class Public methods

2015-06-14 23:05:18