How to: Compress .NET Stream
To compress a .NET stream, do the following:
- Create a ZipArchive class instance.
- Call its ZipArchive.AddStream method and specify a source stream.
- Call the proper ZipArchive.Save method overload to create an archive and save it to a stream.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/compression-library-examples-e4695
using DevExpress.Compression;
public void ArchiveStream() {
using (Stream myStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("DevExpress"))) {
using (Stream myZippedStream = new FileStream("Documents\\ArchiveStream.zip", System.IO.FileMode.Create)) {
using (ZipArchive archive = new ZipArchive()) {
archive.AddStream("myStream", myStream);
archive.Save(myZippedStream);
}
}
}
}