Project

General

Profile

Bug #5948 » zlib.doc.patch

rafadc (Rafael de Castro), 01/30/2012 10:01 PM

View differences:

ext/zlib/zlib.c
*
* == Overview
*
* Access to the zlib library.
* This module provides access to the ZLib library
*
* The zlib compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data. This version of the library supports only one compression method (deflation) but other algorithms will be added later and will have the same stream interface.
* Compression can be done in a single step if the buffers are large enough (for example if an input file is mmap'ed), or can be done by repeated calls of the compression function. In the latter case, the application must provide more input and/or consume the output (providing more output space) before each call.
*
* The compressed data format used by default by the in-memory functions is the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped around a deflate stream, which is itself documented in RFC 1951.
*
* The library also supports reading and writing files in gzip (.gz) format with an interface similar to that of stdio using the functions that start with "gz". The gzip format is different from the zlib format. gzip is a gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
*
* This library can optionally read and write gzip streams in memory as well.
*
* 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.
*
* == Class tree
*
-
ext/zlib/zlib.c
*
* 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.
*
*
* == Sample usage
*
* Using the wrapper to compress strings with default parameters is quite simple:
*
* require "zlib"
*
* data_to_compress = File.read("file_to_compress.data")
*
* puts "Input size: #{data_to_compress.size}"
*
* data_compressed = Zlib::Deflate.deflate(data_to_compress)
*
* puts "Compressed data is:\n#{data_compressed}"
* puts "And its size is #{data_compressed.size}"
*
* uncompressed_data = Zlib::Inflate.inflate(data_compressed)
*
* puts "Uncompressed data is:\n#{uncompressed_data}"
*
* == Class tree
*
* - Zlib::Deflate
-
ext/zlib/zlib.c
*
* This module provides access to the ZLib library
*
* The zlib compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data. This version of the library supports only one compression method (deflation) but other algorithms will be added later and will have the same stream interface.
* Compression can be done in a single step if the buffers are large enough (for example if an input file is mmap'ed), or can be done by repeated calls of the compression function. In the latter case, the application must provide more input and/or consume the output (providing more output space) before each call.
* The zlib compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data.
*
* The compressed data format used by default by the in-memory functions is the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped around a deflate stream, which is itself documented in RFC 1951.
*
-
ext/zlib/zlib.c
*
* == Overview
*
* This module provides access to the ZLib library
* This module provides access to the {zlib library}[http://zlib.net]. Zlib is designed to be a 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 data format is itself portable across platforms.
*
* The zlib compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data.
*
-
ext/zlib/zlib.c
* If +string+ is nil, this method finishes the
* stream, just like Zlib::ZStream#finish.
*
* == Usage
* == Sample Usage
*
* comp = Zlib.deflate(File.read("big.file"))
* or
* comp = Zlib.deflate(File.read("big.file"), Zlib::FULL_FLUSH)
* === Compressing a string with best compression
*
* zlib = Zlib::Deflate.new(Zlib::BEST_COMPRESSION)
* compressed_string = zlib.deflate(string, Zlib::FINISH)
* zlib.close
*
* puts "Compressed string is: #{compressed_string}"
*
* puts "Decompressed string is #{Zlib::Inflate.inflate(compressed_string)}"
*/
static VALUE
rb_deflate_deflate(int argc, VALUE *argv, VALUE obj)
-
ext/zlib/zlib.c
* == Arguments
*
* +level+::
* An Integer compression level between
* BEST_SPEED and BEST_COMPRESSION
* An Integer compression level between 0 and 9. The following constants have
* been defined to make code more readable:
*
* [Z_NO_COMPRESSION = 0]
* [Z_BEST_SPEED = 1]
* [Z_BEST_COMPRESSION = 9]
*
* +windowBits+::
* An Integer for the windowBits size. Should be
* in the range 8..15, larger values of this parameter
-
ext/zlib/zlib.c
*
* [Z_NO_COMPRESSION = 0]
* [Z_BEST_SPEED = 1]
* [Z_DEFAULT_COMPRESSION = 6]
* [Z_BEST_COMPRESSION = 9]
*
* +windowBits+::
-
ext/zlib/zlib.c
* the internal compression state.
* Between DEF_MEM_LEVEL and MAX_MEM_LEVEL
* +strategy+::
* A parameter to tune the compression algorithm. Use the
* DEFAULT_STRATEGY for normal data, FILTERED for data produced by a
* filter (or predictor), HUFFMAN_ONLY to force Huffman encoding only (no
* string match).
* A parameter to tune the compression algorithm.
* [Z_DEFAULT_STRATEGY] For normal data
* [HUFFMAN_ONLY] To force Huffman encoding only (no string match).
* [FILTERED] For data produced by a filter (or predictor). The effect
* of FILTERED is to force more Huffman coding 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.
*
* == Description
*
-
ext/zlib/zlib.c
* An Integer compression level between 0 and 9. The following constants have
* been defined to make code more readable:
*
* [Z_NO_COMPRESSION = 0]
* [Z_BEST_SPEED = 1]
* [Z_DEFAULT_COMPRESSION = 6]
* [Z_BEST_COMPRESSION = 9]
* * Z_NO_COMPRESSION = 0
* * Z_BEST_SPEED = 1
* * Z_DEFAULT_COMPRESSION = 6
* * Z_BEST_COMPRESSION = 9
*
* +windowBits+::
* An Integer for the windowBits size. Should be
-
ext/zlib/zlib.c
* in the range 8..15, larger values of this parameter
* result in better at the expense of memory usage.
* +memlevel+::
* Specifies how much memory should be allocated for
* the internal compression state.
* Between DEF_MEM_LEVEL and MAX_MEM_LEVEL
* The memLevel parameter specifies how much memory should be allocated
* for the internal compression state. memLevel=1 uses minimum memory but is
* slow and reduces compression ratio; memLevel=9 uses maximum memory for
* optimal speed. The default value is 8. Two constants are defined:
* * DEF_MEM_LEVEL = 8
* * MAX_MEM_LEVEL = 9
* +strategy+::
* A parameter to tune the compression algorithm.
* [Z_DEFAULT_STRATEGY] For normal data
-
ext/zlib/zlib.c
* * Z_BEST_COMPRESSION = 9
*
* +windowBits+::
* An Integer for the windowBits size. Should be
* in the range 8..15, larger values of this parameter
* result in better at the expense of memory usage.
* An Integer for the windowBits size (the size of the history buffer).
* Should be in the range 8..15. Larger values of this parameter
* result in better compression at the expense of memory usage.
* +memlevel+::
* The memLevel parameter specifies how much memory should be allocated
* for the internal compression state. memLevel=1 uses minimum memory but is
-
ext/zlib/zlib.c
* String
*
* +flush+::
* Integer representing a flush code. Either NO_FLUSH,
* SYNC_FLUSH, FULL_FLUSH, or FINISH. See zlib.h for details.
* Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
* decide how much data to accumulate before producing output, in order to
* maximize compression.
* Integer representing a flush mode.
* [NO_FLUSH] Normally the parameter flush is set to NO_FLUSH, which
* allows deflate to decide how much data to accumulate before
* producing output, in order to maximize compression.
* [SYNC_FLUSH] All pending output is flushed to the output buffer
* and the output is aligned on a byte boundary, so that the
* decompressor can get all input data available so far. (In
* particular avail_in is zero after the call if enough output
* space has been provided before the call.) Flushing may
* degrade compression for some compression algorithms and so
* it should be used only when necessary. This completes the
* current deflate block and follows it with an empty stored
* block that is three bits plus filler bits to the next byte,
* followed by four bytes (00 00 ff ff)
* [FULL_FLUSH] All output is flushed 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. Using FULL_FLUSH too
* often can seriously degrade compression.
* [FINISH] Pending input is processed, pending output is flushed.
*
* == Description
*
-
ext/zlib/zlib.c
*
* === Compressing a string with best compression
*
* zlib = Zlib::Deflate.new(Zlib::BEST_COMPRESSION)
* compressed_string = zlib.deflate(string, Zlib::FINISH)
* zlib.close
* zstream = Zlib::Deflate.new(Zlib::BEST_COMPRESSION)
* compressed_string = zstream.deflate(string, Zlib::FINISH)
* zstream.close
*
* puts "Compressed string is: #{compressed_string}"
*
-
ext/zlib/zlib.c
* == Arguments
*
* +windowBits+::
* An Integer for the windowBits size. Should be
* in the range 8..15, larger values of this parameter
* result in better at the expense of memory usage.
*
* An Integer whose meaning depends on the value
* [0] To request that inflate use the window size in the zlib header of the
* compressed stream.
* [Between 8 and 15] In this case, +windowBits+ determines the window size.
* +inflate+ will then process raw deflate data, not
* looking for a zlib or gzip header, not generating a
* check value, and not looking for any check values for
* comparison at the end of the stream. This is for use
* with other formats that use the deflate compressed data
* format such as zip. Those formats provide their own
* check values.
* [Greater than 15] windowBits can also be greater than 15 for optional
* gzip decoding. Add 32 to windowBits to enable zlib and
* gzip decoding with automatic header detection, or add
* 16 to decode only the gzip format (the zlib format will
* throw a Zlib::DataError).
* == Description
*
* Creates a new inflate stream for decompression. See zlib.h for details
* of the argument. If +window_bits+ is +nil+, the default value is used.
* Creates a new inflate stream for decompression. If +window_bits+ is +nil+,
* the default value Zlib::MAX_WBITS is used.
*
* == Example
*
-
ext/zlib/zlib.c
* An Integer compression level between 0 and 9. The following constants have
* been defined to make code more readable:
*
* * Z_NO_COMPRESSION = 0
* * Z_BEST_SPEED = 1
* * Z_DEFAULT_COMPRESSION = 6
* * Z_BEST_COMPRESSION = 9
* * NO_COMPRESSION = 0
* * BEST_SPEED = 1
* * DEFAULT_COMPRESSION = 6
* * BEST_COMPRESSION = 9
*
* +windowBits+::
* An Integer for the windowBits size (the size of the history buffer).
......
* * MAX_MEM_LEVEL = 9
* +strategy+::
* A parameter to tune the compression algorithm.
* [Z_DEFAULT_STRATEGY] For normal data
* [DEFAULT_STRATEGY] For normal data
* [HUFFMAN_ONLY] To force Huffman encoding only (no string match).
* [FILTERED] For data produced by a filter (or predictor). The effect
* of FILTERED is to force more Huffman coding and less string
-
ext/zlib/zlib.c
*
* == Overview
*
* This module provides access to the {zlib library}[http://zlib.net]. Zlib is designed to be a 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.
* This module provides access to the {zlib library}[http://zlib.net]. Zlib is
* designed to be a 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 data format is itself portable across platforms.
*
* The zlib compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data.
* The zlib compression library provides in-memory compression and
* decompression functions, including integrity checks of the uncompressed
* data.
*
* The compressed data format used by default by the in-memory functions is the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped around a deflate stream, which is itself documented in RFC 1951.
* The compressed data format used by default by the in-memory functions is the
* zlib format, which is a zlib wrapper documented in RFC 1950, wrapped around
* a deflate stream, which is itself documented in RFC 1951.
*
* The library also supports reading and writing files in gzip (.gz) format with an interface similar to that of stdio using the functions that start with "gz". The gzip format is different from the zlib format. gzip is a gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
* The library also supports reading and writing files in gzip (.gz) format
* with an interface similar to that of stdio using the functions that start
* with "gz". The gzip format is different from the zlib format. gzip is a gzip
* wrapper, documented in RFC 1952, wrapped around a deflate stream.
*
* This library can optionally read and write gzip streams in memory as well.
*
* 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.
* 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.
*
*
* == Sample usage
-
ext/zlib/zlib.c
* <tt>SYNC_FLUSH</tt> is used as flush. This method is just provided
* to improve the readability of your Ruby program.
*
* Please visit your zlib.h for a deeper detail on NO_FLUSH, SYNC_FLUSH, FULL_FLUSH, and FINISH
* Please visit Zlib::Deflate#deflate for a deeper detail on NO_FLUSH, SYNC_FLUSH, FULL_FLUSH, and FINISH
*
*/
static VALUE
......
* buffer.
*
* +level+::
* An Integer compression level between
* BEST_SPEED and BEST_COMPRESSION
* See Zlib::Deflate.new
* +strategy+::
* A parameter to tune the compression algorithm. Use the
* DEFAULT_STRATEGY for normal data, FILTERED for data produced by a
* filter (or predictor), HUFFMAN_ONLY to force Huffman encoding only (no
* string match).
* See Zlib::Deflate.new
*
*/
static VALUE
-
ext/zlib/zlib.c
* Using the wrapper to compress strings with default parameters is quite simple:
*
* require "zlib"
*
* data_to_compress = File.read("file_to_compress.data")
*
* data_to_compress = File.read("file_to_compress.data")
*
* puts "Input size: #{data_to_compress.size}"
* #=> Input lenght: 2347740
*
* data_compressed = Zlib::Deflate.deflate(data_to_compress)
*
* puts "Compressed data is:\n#{data_compressed}"
* puts "Compressed data is:\n#{data_compressed}"
* #=> Compressed data is:
* x????r?%?.3?C?Cuoe??K??(???M??$?????@?輐B}???=2?z???S[?%?ï˗?mb?]
* [...]
*
* puts "And its size is #{data_compressed.size}"
*
* #=> And its size is 887238
*
* uncompressed_data = Zlib::Inflate.inflate(data_compressed)
*
* puts "Uncompressed data is:\n#{uncompressed_data}"
* #=> Uncompressed data is:
* The Project Gutenberg EBook of Don Quixote, by Miguel de Cervantes
* [...]
*
* == Class tree
*
-
ext/zlib/zlib.c
* zstream.close
*
* puts "Compressed string is: #{compressed_string}"
* #=> Compressed string is: ڜ??r?%?.3?C?Cu???Rwץ[?(???͋6I??f?<???D&:/?P|-w????c?f
* [...]
*
* puts "Decompressed string is #{Zlib::Inflate.inflate(compressed_string)}"
* #=> Decompressed string is The Project Gutenberg EBook of Don Quixote, by Miguel de Cervantes
*/
static VALUE
rb_deflate_deflate(int argc, VALUE *argv, VALUE obj)
-
ext/zlib/zlib.c
*
* data_compressed = Zlib::Deflate.deflate(data_to_compress)
*
* puts "Compressed data is:\n#{data_compressed}"
* #=> Compressed data is:
* x????r?%?.3?C?Cuoe??K??(???M??$?????@?輐B}???=2?z???S[?%?ï˗?mb?]
* [...]
* puts "Compressed data is:#{data_compressed}"
* #=> Compressed data is: x????r?%?.3?C?Cuoe??K??(???M??$?????@?輐B}???=2?z...
*
* puts "And its size is #{data_compressed.size}"
* #=> And its size is 887238
*
* uncompressed_data = Zlib::Inflate.inflate(data_compressed)
*
* puts "Uncompressed data is:\n#{uncompressed_data}"
* #=> Uncompressed data is:
* The Project Gutenberg EBook of Don Quixote, by Miguel de Cervantes
* [...]
* puts "Uncompressed data is:#{uncompressed_data}"
* #=> Uncompressed data is:The Project Gutenberg EBook of Don Quixote...
*
* == Class tree
*
......
* == Arguments
*
* +string+::
* String
* String to deflate
*
* +flush+::
* Integer representing a flush mode.
* Flush mode. You can use four constants to specify flush mode.
* [NO_FLUSH] Normally the parameter flush is set to NO_FLUSH, which
* allows deflate to decide how much data to accumulate before
* producing output, in order to maximize compression.
......
* zstream.close
*
* puts "Compressed string is: #{compressed_string}"
* #=> Compressed string is: ڜ??r?%?.3?C?Cu???Rwץ[?(???͋6I??f?<???D&:/?P|-w????c?f
* [...]
* #=> Compressed string is: ڜ??r?%?.3?C?Cu???Rwץ[?(???͋6I??...
*
* puts "Decompressed string is #{Zlib::Inflate.inflate(compressed_string)}"
* #=> Decompressed string is The Project Gutenberg EBook of Don Quixote, by Miguel de Cervantes
* #=> Decompressed string is The Project Gutenberg EBook of Don Quixote...
*/
static VALUE
rb_deflate_deflate(int argc, VALUE *argv, VALUE obj)
......
*
* == Example
*
* cf = File.open("compressed.file")
* ucf = File.open("uncompressed.file", "w+")
* zi = Zlib::Inflate.new(Zlib::MAX_WBITS)
* compressed_file = File.open("compressed.gz")
* uncompressed_file = File.open("uncompressed.file", "w+")
* zip = Zlib::Inflate.new(16)
*
* ucf << zi.inflate(cf.read)
* uncompressed_file << zip.inflate(compressed_file.read)
*
* ucf.close
* zi.close
* cf.close
* uncompressed_file.close
* zip.close
* compressed_file.close
*
* or
*
    (1-1/1)