コード例 #1
0
        public static byte[] Compress(byte[] buffer, CompressionType?compressionType = null)
        {
            switch (compressionType)
            {
            case CompressionType.GZip:
                return(GZipHelper.Compress(buffer));

            default:
                return(buffer);
            }
        }
コード例 #2
0
        ///// <summary>
        ///// დეკომპრესია ბაიტების მასივის
        ///// </summary>
        ///// <param name="gzbuffer">დაკომპრესული ბაიტების მასივი (GZip)</param>
        ///// <returns>ჩვეულებრივი ბაიტების მასივი</returns>
        //private static byte[] DecompressOld(byte[] gzbuffer)
        //{
        //    if (gzbuffer == null) return null;

        //    using (var ms = new MemoryStream())
        //    {
        //        var msgLength = BitConverter.ToInt32(gzbuffer, 0);
        //        ms.Write(gzbuffer, 4, gzbuffer.Length - 4);

        //        var buffer = new byte[msgLength];

        //        ms.Position = 0;
        //        using (var zip = new GZipStream(ms, CompressionMode.Decompress))
        //        {
        //            zip.Read(buffer, 0, buffer.Length);

        //            ms.Flush();

        //            return buffer;
        //        }
        //    }
        //}
        public static byte[] Decompress(byte[] compressedBuffer, CompressionType?compressionType = null)
        {
            switch (compressionType)
            {
            case CompressionType.GZip:
                return(GZipHelper.Decompress(compressedBuffer));

            //case CompressType.GzipOldCore:
            //    return DecompressOld(compressedBuffer);
            default:
                return(compressedBuffer);
            }
        }