# Poco

# class DeflatingStreamBuf

Library: Foundation
Package: Streams
Header: Poco/DeflatingStream.h

## Description

This is the streambuf class used by DeflatingInputStream and DeflatingOutputStream. The actual work is delegated to zlib (see http://zlib.net). Both zlib (deflate) streams and gzip streams are supported. Output streams should always call close() to ensure proper completion of compression. A compression level (0 to 9) can be specified in the constructor.

## Inheritance

Direct Base Classes: BufferedStreamBuf

All Base Classes: BufferedStreamBuf

## Member Summary

Member Functions: close, readFromDevice, sync, writeToDevice

## Enumerations

### CompressionLevel

Constants for compression levels. Note to maintainers: These must be kept in sync with the constants defined by zlib.

DEFAULT_COMPRESSION = - 1

NO_COMPRESSION = 0

BEST_SPEED = 1

BEST_COMPRESSION = 9

### StreamType

STREAM_ZLIB

Create a zlib header, use Adler-32 checksum.

STREAM_GZIP

Create a gzip header, use CRC-32 checksum.

## Constructors

### DeflatingStreamBuf

DeflatingStreamBuf(
std::istream & istr,
StreamType type,
int level
);

Creates a DeflatingStreamBuf for compressing data read from the given input stream.

### DeflatingStreamBuf

DeflatingStreamBuf(
std::istream & istr,
int windowBits,
int level
);

Creates a DeflatingStreamBuf for compressing data read from the given input stream.

Please refer to the zlib documentation of deflateInit2() for a description of the windowBits parameter.

### DeflatingStreamBuf

DeflatingStreamBuf(
std::ostream & ostr,
StreamType type,
int level
);

Creates a DeflatingStreamBuf for compressing data passed through and forwarding it to the given output stream.

### DeflatingStreamBuf

DeflatingStreamBuf(
std::ostream & ostr,
int windowBits,
int level
);

Creates a DeflatingStreamBuf for compressing data passed through and forwarding it to the given output stream.

Please refer to the zlib documentation of deflateInit2() for a description of the windowBits parameter.

## Destructor

### ~DeflatingStreamBuf

~DeflatingStreamBuf() override;

Destroys the DeflatingStreamBuf.

## Member Functions

### close

int close();

Finishes up the stream.

Must be called when deflating to an output stream.

### readFromDevice

std::streamsize readFromDevice(
char * buffer,
std::streamsize length
) override;

### sync

int sync() override;

### writeToDevice

std::streamsize writeToDevice(
const char * buffer,
std::streamsize length
) override;