Introduction to the formatted compressed stream classes

Glossary Item Box

Introduction

The Xceed.Compression.Formats namespace defines the GZipCompressedStream class which reads and writes GZip formatted compressed data, the XceedCompressedStream class which reads and writes Xceed formatted compressed data and the ZLibCompressedStream class which reads and writes ZLib compressed data. 

Like the CompressedStream class, these classes can be constructed around any kind of Stream object to compress data that is written to the stream and decompress data that is read from the stream. 

All of the formatted compressed stream classes derive from the abstract FormattedCompressedStream class. The FormattedCompressedStream class represents a stream which writes the header and footer of formatted compressed streams.  

 

 

GZipCompressedStream , XceedCompressedStream and ZLibCompresedStream classes

The formatted compressed stream classes, like the CompressedStream class, are pass-through streams that apply compression to data being written to and decompression to data being read from an inner stream. 

Keep in mind that once a formatted compressed stream class is created around a stream, it becomes the owner of the stream and both streams will be closed when the formatted compressed stream is closed. To bypass this behavior, you can set the Transient property of the formatted compressed stream class to true. This will prevent the inner stream from being closed along with it. 

The following diagram represents the relationship between the formatted compressed stream classes and the Stream classes:

 

ChecksumStream class

The ChecksumStream class is a pass-through stream that calculates an Adler32 or a CRC32 checksum on the data read or written to the inner stream.

Compress and Decompress methods

Each of the formatted compressed stream classes expose static Compress and Decompress methods that allow quick and easy compression and decompression of byte arrays.