How to: Compress Byte Array
To compress a byte array, do the following:
- Create a ZipArchive class instance.
- Call its ZipArchive.AddByteArray method to specify a byte array to compress.
- Call the ZipArchive.Save method to create an archive and save it to a stream.
This code snippet adds a byte array to an archive as an item with the name “myByteArray” and outputs zipped data to the stream.
using DevExpress.Compression;
public void ArchiveByteArray() {
byte[] myByteArray = Enumerable.Repeat((byte)0x78, 10000).ToArray();
using (Stream myZippedStream = new FileStream("ArchiveByteArray.zip", FileMode.Create)) {
using (ZipArchive archive = new ZipArchive()) {
archive.AddByteArray("myByteArray", myByteArray);
archive.Save(myZippedStream);
}
}
}