Back to Arangodb

Zlib Filters

3rdParty/boost/1.78.0/libs/iostreams/doc/classes/zlib.html

3.12.9.111.4 KB
Original Source

Zlib Filters

OverviewAcknowledgmentsHeadersSynopsisReferencenamespace boost::iostreams::zlibClass zlib_paramsClass template zlib_compressorClass template zlib_decompressorClass zlib_errorExamplesInstallation

Overview

The class templates basic_zlib_compressor and basic_zlib_decompressor perform compression and decompression in the ZLIB format ([Deutsch1]) using Jean-loup Gailly's and Mark Adler's zlib compression library ([Gailly]).

The zlib Filters are DualUseFilters so that they may be used for either input or output. Most commonly, however, the compression Filters will be used for output and the decompression Filters for input.

Acknowledgments

The zlib Filters were influences by the work of Jeff Garland ([Garland]) and Jonathan de Halleux ([de Halleux]).

Thanks to Jean-loup Gailly and Mark Adler for making their excellent library available to the public with a Boost-compatible license.

Headers

<boost/iostreams/filter/zlib.hpp>

Synopsis

namespaceboost {namespaceiostreams {namespace[zlib](#constants){// Compression levelsexternconstint[no\_compression](#no_compression);externconstint[best\_speed](#best_speed);externconstint[best\_compression](#best_compression);externconstint[default\_compression](#default_compression);// Compression methodsexternconstint[deflated](#deflated);// Compression strategiesexternconstint[default\_strategy](#default_strategy);externconstint[filtered](#filtered);externconstint[huffman\_only](#huffman_only);// Status codesexternconstint[stream\_error](#stream_error);externconstint[version\_error](#version_error);externconstint[data\_error](#data_error);externconstint[buf\_error](#buf_error);

}// End namespace boost::iostreams::zlibstruct[zlib\_params](#zlib_params);template<typenameAlloc = std::allocator<char> >struct[basic\_zlib\_compressor](#basic_zlib_compressor);template<typenameAlloc = std::allocator<char> >struct[basic\_zlib\_decompressor](#basic_zlib_decompressor);typedefbasic_zlib_compressor<>zlib\_compressor;typedefbasic_zlib_decompressor<>zlib\_decompressor;class[zlib\_error](#zlib_error);

} }// End namespace boost::io

Reference

Namespace boost::iostreams::zlib

The namespace boost::iostreams::zlib contains integral constants used to configure zlib Filters and to report errors. The constants have the following interpretations. (See [Gailly] for additional details.)

ConstantInterpretation
no_compressionCompression-level constant specifying that no compression should be performed. Equal to Z_NO_COMPRESSION.
best_speedCompression-level constant requesting the fasted compression. Equal to Z_BEST_SPEED.
best_compression.Compression-level constant requesting the best compression ratio. Equal to Z_BEST_COMPRESSION.
default_compressionDefault compression level. Equal to Z_DEFAULT_COMPRESSION.
deflatedCompression method constant; currently the only supported method. Equal to Z_DEFLATED.
default_strategyCompression strategy constant. Equal to Z_DEFAULT_STRATEGY.
filteredCompression strategy constant. Equal to Z_FILTERED.
huffman_onlyCompression strategy constant. Equal to Z_HUFFMAN_ONLY.
stream_errorError code used to indicate that one of the members of zlib_params is invalid; may also indicate an internal Iostreams library error. Equal to Z_STREAM_ERROR.
version_errorError code used to indicate that data was compressed with an incompatible version of zlib. Equal to Z_VERSION_ERROR.
data_errorError code used to indicate that a compressed datastream is corrupted. Equal to Z_DATA_ERROR.
buf_errorError code indicating an internal Iostreams library error. Equal to Z_BUF_ERROR.

Class zlib_params

Description

Encapsulates the parameters used to configure basic_zlib_compressor and basic_zlib_decompressor.

Synopsis

structzlib\_params{// Non-explicit constructor[zlib\_params](#zlib_params_constructors)(intlevel = zlib::default_compression,intmethod = zlib::deflated,intwindow_bits = default value,intmem_level = default value,intstrategy = zlib::default_strategy,boolnoheader = false );intlevel;intmethod;intwindow_bits;intmem_level;intstrategy;boolnoheader;
};

zlib_params::zlib_params

zlib_params(intlevel = zlib::default_compression,intmethod = zlib::deflated,intwindow_bits = default value,intmem_level = default value,intstrategy = zlib::default_strategy,boolnoheader = false );

Constructs a zlib_params object, where the parameters have the following interpretations:

| | | | level | - | Compression level. Must be equal to zlib::default_compression or a value in the range 0-9. The value 0 yields no compression, while 9 yields the best compression ratio. Affects compression only. | | method | - | Compression method. Must equal zlib::deflated. Affects compression only. | | window_bits | - | The base two logarithm of the window size. Must be in the range 8-15; defaults to 15. | | mem_level | - | Specifies the amount of memory to be used. Must be in the range 1-9; defaults to 8. Affects compression only. | | strategy | - | Must be zlib::default_strategy, zlib::filtered or zlib::huffman_only. Affects compression only. | | noheader | - | True if the ZLIB header and trailing ADLER-32 checksum should be omitted (see [Deutsch1]). This results in compression according to the deflate specification (see [Deutsch2]). |

See [Gailly] for additional details.

Class template basic_zlib_compressor

Description

Model of DualUseFilter which performs compression using zlib ([Gailly]).

Synopsis

template<typename[Alloc](#basic_zlib_compressor_params)= std::allocator<char> >struct[basic\_zlib\_compressor](#basic_zlib_compressor_params){typedefcharchar_type;typedefimplementation-definedcategory;[basic\_zlib\_compressor](#basic_zlib_compressor_constructors)(const[zlib\_params](#zlib_params)& =zlib::default\_compression,
                           std::streamsize buffer_size =default value);// DualUseFilter members.};typedefbasic_zlib_compressor<>zlib\_compressor;

Template Parameters

| | | | Alloc | - | A C++ standard library allocator type ([ISO], 20.1.5), used to allocate a character buffer and to configure zlib. |

basic_zlib_compressor::basic_zlib_compressor

basic_zlib_compressor(const[zlib\_params](#zlib_params)& =zlib::default\_compression,
                           std::streamsize buffer_size =default value);

Constructs an instance of basic_zlib_compressor with the given parameters and buffer size. Since a zlib_params object is implicitly constructible from an int representing a compression level, an int may be passed as the first constructor argument.

Class template basic_zlib_decompressor

Description

Model of DualUseFilter which performs decompression using zlib ([Gailly]).

Synopsis

template<typename[Alloc](#basic_zlib_decompressor_params)= std::allocator<char> >struct[basic\_zlib\_decompressor](#basic_zlib_decompressor_params){typedefcharchar_type;typedefimplementation-definedcategory;[basic\_zlib\_decompressor](#basic_zlib_decompressor_constructors)(intwindow_bits =default value, 
                             std::streamsize buffer_size =default value);[basic\_zlib\_decompressor](#basic_zlib_decompressor_constructors)(const[zlib\_params](#zlib_params)&,
                             std::streamsize buffer_size =default value);// DualUseFilter members.};typedefbasic_zlib_decompressor<>zlib\_decompressor;

Template Parameters

| | | | Alloc | - | A C++ standard library allocator type ([ISO], 20.1.5), used to allocate a character buffer and to configure zlib. |

basic_zlib_decompressor::basic_zlib_decompressor

basic_zlib_decompressor(intwindow_bits =default value, 
                             std::streamsize buffer_size =default value);
    basic_zlib_decompressor(const[zlib\_params](#zlib_params)&,
                             std::streamsize buffer_size =default value);

The first member constructs an instance of basic_zlib_decompressor with the given parameters and buffer size. The second member constructs an instance of basic_zlib_decompressor with the given window bits value and buffer size. Other parameters affecting decompression are set to default values.

Class zlib_error

Description

Used by the zlib Filters to report errors.

Synopsis

classzlib\_error:publicstd::ios_base::failure {public:[zlib\_error](#zlib_error_constructor)(interror);int[error](#zlib_error_error)() const;
};

zlib_error::zlib_error

zlib_error(interror);

Constructs an instance of zlib_error with the given error code from the namespace boost::iostreams::zlib.

zlib_error::error

voiderror()const;

Returns an error code from the namespace boost::iostreams::zlib.

Examples

The following code decompresses data from a file and writes it to standard output.

#include\<fstream\>#include\<iostream\>#include[\<boost/iostreams/filtering\_streambuf.hpp\>](../../../../boost/iostreams/filtering_streambuf.hpp)#include[\<boost/iostreams/copy.hpp\>](../../../../boost/iostreams/copy.hpp)#include[\<boost/iostreams/filter/zlib.hpp\>](../../../../boost/iostreams/filter/zlib.hpp)int main() 
{usingnamespacestd;

    ifstream file("hello.z", ios_base::in | ios_base::binary);
    filtering_streambuf<input> in;
    in.push(zlib_decompressor());
    in.push(file);
    boost::iostreams::copy(in, cout);
}

Installation

The zlib Filters depend on the third-party zlib library, which is not included in the Boost distribution. Prebuilt zlib binaries are available on most UNIX and UNIX-like systems, and will be found automatically by the Boost build system. Windows users can obtain prebuilt binaries at the zlib homepage. Users can also configure the Boost Iostream library to build zlib from the source code, which is available at the zlib homepage. For details on configuring the build system to find your zlib installation, please see Installation.


© Copyright 2008 CodeRage, LLC
© Copyright 2004-2007 Jonathan Turkanis

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)