Zip Text String - CSharp System.IO.Compression

CSharp examples for System.IO.Compression:Zip

Description

Zip Text String

Demo Code


using System.Text;
using System.IO.Compression;
using System.IO;//  w  w  w .jav  a  2  s.  co  m
using System.Collections.Generic;
using System;

public class Main{
        public static string ZipText(string rawText)
        {
            byte[] rawBinary = ASCIIEncoding.ASCII.GetBytes(rawText);

            byte[] compressedBinary = ZipBinary(rawBinary);

            return Convert.ToBase64String(compressedBinary);
        }
        public static byte[] ZipBinary(byte[] rawSource)
        {
            memDestination = new MemoryStream();
            memSource = new MemoryStream(rawSource);
            gzipStream = new GZipStream(memDestination, CompressionMode.Compress);

            Streamer.CopyStream(memSource, gzipStream);

            gzipStream.Close();

            return memDestination.ToArray();
        }
}

Related Tutorials