Compress byte array with GZipStream - CSharp System.IO.Compression

CSharp examples for System.IO.Compression:GZip

Description

Compress byte array with GZipStream

Demo Code


using System.Text;
using System.IO.Compression;
using System.IO;//from   www.  java2s. c o  m
using System;

public class Main{
        public static byte[] Compress(byte[] decompressedData)
      {
         if (decompressedData == null) return null;
         var textStream = new MemoryStream();
         var zip = new GZipStream(textStream, CompressionMode.Compress);
         zip.Write(decompressedData, 0, decompressedData.Length);
         return textStream.ToArray();
      }
}

Related Tutorials