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.
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:
Class | Description | Notes |
---|---|---|
CompressedStream |
Reads and writes compressed data from any method from CompressionMethod. Compression method not stored in the data. No data integrity. No encryption support. |
This is the class used by Xceed Zip for .NET to compress/decompress zipped data. Usage only recommended when compressing to and from memory buffers where the compression method is tracked and there is no chance of data corruption. Can be used in advanced scenarios to mimic the Zip format. |
XceedCompressedStream |
Reads and writes compressed data from any method from CompressionMethod in a lightweight proprietary format. Compression method and Adler32 CRC stored in the data. Encryption supported (Zip traditional encryption only). |
Good general purpose class for streaming compression where the data is meant for any destination: disk, memory, network, etc. Usage recommended is all situations. Convenient. No need to remember the compression method. Small header and footer. Will automatically detect tempering with the CRC. |
XceedCompressedStreamEx | The same as XceedCompressedStream but supports reading and writing compressed data that will be consumed by Xceed Zip for ActiveX. | If interoperability is required with Xceed Zip for ActiveX, use this class. Functionality and performance is exactly the same as XceedCompressedStream. |
GZipCompressedStream |
Reads and writes compressed data in the well known GZip format. Compression method and CRC stored in the data. Supports some metadata like a filename, comment, last write date. No encryption support. |
The GZip format is popular and used on a lot of systems. Good format for interoperability. The compression used by GZip is always Deflate. |
ZLibCompressedStream |
Reads and writes compressed data from any method from CompressionMethod in a format specified by the ZLib compression library. Compression method not stored in the data. No data integrity. No encryption support. |
Usage only recommended if comparibility with ZLib compression library is required. Otherwise, use XceedCompressedStream. |
BZip2CompressedStream |
Reads and writes compressed data using the CompressionMethod.BZip2 method. Compression method not stored in the data. No data integrity. No encryption support. |
Usage only recommended when compressing to and from memory buffers where the compression method is tracked and there is no chance of data corruption. |
LZMACompressedStream |
Reads and writes compressed data using the CompressionMethod.LZMA method. Compression method not stored in the data. No data integrity. No encryption support. |
Offers convenient, detailed and precise control over the compression options with the LZMAOptions class. Something not available when using the other classes. Usage only recommended when compressing to and from memory buffers where the compression method is tracked and there is no chance of data corruption. |
PPMdCompressedStream |
Reads and writes compressed data using the CompressionMethod.PPMd method. Compression method not stored in the data. No data integrity. No encryption support. |
Usage only recommended when compressing to and from memory buffers where the compression method is tracked and there is no chance of data corruption. |
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.
Each of the formatted compressed stream classes expose static Compress and Decompress methods that allow easy compression and decompression of byte arrays.