Click here to Skip to main content
15,896,111 members
Articles / Programming Languages / XML

netTierGenerator

Rate me:
Please Sign up or sign in to vote.
4.81/5 (20 votes)
30 Nov 2008CPOL14 min read 67.6K   2.8K   108  
A 3-tier application framework and code generation tool - the way for rapid and effective development.
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;

namespace Sample.Common.Util
{
    public static class GZipHelper
    {
        public static byte[] Compress(byte[] val)
        {
            byte[] result;
            using (MemoryStream memoryStream = new MemoryStream())
            using (GZipStream zipStream = new GZipStream(memoryStream, CompressionMode.Compress))
            {
                zipStream.Write(val, 0, val.Length);
                zipStream.Close();
                result = memoryStream.ToArray();
            }

            return result;
        }
        public static byte[] Decompress(byte[] val)
        {
            byte[] result = null;
            using (MemoryStream memoryStream = new MemoryStream(val))
            using (GZipStream zipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
            {
                GZipHelper.ReadAllBytesFromStream(zipStream, out result);
            }

            return result;
        }
        private static void ReadAllBytesFromStream(Stream stream, out byte[] buffer)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                int readByte = 0;
                while (true)
                {
                    readByte = stream.ReadByte();
                    if (readByte == -1)
                    {
                        break;
                    }
                    memoryStream.WriteByte((byte)readByte);
                }

                buffer = new byte[memoryStream.Length];
                buffer = memoryStream.ToArray();
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions