コード例 #1
0
ファイル: Util.cs プロジェクト: bludee/GameBase
        /// <summary>
        /// 压缩byte[]
        /// </summary>
        /// <returns>The bytes.</returns>
        /// <param name="data">Data.</param>
        public static byte[] CompressBytes(byte[] data)
        {
            MemoryStream ms = new MemoryStream();

            ICSharpCode.SharpZipLib.GZip.GZipOutputStream gzp = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(ms);
            gzp.Write(data, 0, data.Length);
            gzp.Close();
            return(ms.ToArray());
        }
コード例 #2
0
ファイル: zip.cs プロジェクト: ximenchuifeng/Mdx.Core
        /// <summary>
        /// 压缩字节数组
        /// 返回:已压缩的字节数组
        /// </summary>
        /// <param name="byteData">待压缩的字节数组</param>
        /// <returns></returns>
        public static byte[] CompressBytes(byte[] byteData)
        {
            var o = new MemoryStream();
            var s = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(o);

            s.Write(byteData, 0, byteData.Length);
            s.Close();
            o.Flush();
            o.Close();
            return(o.ToArray());
        }
コード例 #3
0
        public static byte[] GCompress(byte[] data)
        {
            byte[] result = null;

            using (MemoryStream ms = new MemoryStream())
                using (Stream s = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(ms))
                {
                    s.Write(data, 0, data.Length);
                    s.Close();
                    result = ms.ToArray();
                }

            return(result);
        }
コード例 #4
0
ファイル: GZip.cs プロジェクト: atom-chen/shisanshui-1
        private static void CreateZipFile(string lpSourceFile, string lpZipFile, GZipResult result)
        {
            byte[]     buffer;
            FileStream fsOut = null;
            FileStream fsIn  = null;

            ICSharpCode.SharpZipLib.GZip.GZipOutputStream gzip = null;
            // compress the file into the zip file
            try
            {
                fsOut = new FileStream(lpZipFile, FileMode.Create, FileAccess.Write, FileShare.None);
                gzip  = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(fsOut);

                fsIn   = new FileStream(lpSourceFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                buffer = new byte[fsIn.Length];
                fsIn.Read(buffer, 0, buffer.Length);
                fsIn.Close();
                fsIn = null;

                // compress to the zip file
                gzip.Write(buffer, 0, buffer.Length);

                result.ZipFileSize        = fsOut.Length;
                result.CompressionPercent = GetCompressionPercent(result.TempFileSize, result.ZipFileSize);
            }
            catch
            { //(Exception ex1)
                result.Errors = true;
            }
            finally
            {
                if (gzip != null)
                {
                    gzip.Close();
                    gzip = null;
                }
                if (fsOut != null)
                {
                    fsOut.Close();
                    fsOut = null;
                }
                if (fsIn != null)
                {
                    fsIn.Close();
                    fsIn = null;
                }
            }
        }
コード例 #5
0
ファイル: DataOper.cs プロジェクト: HX-Hendrix/Shbo.Tools
        /// <summary>
        /// 压缩字符串
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string Compress(string param)
        {
            byte[] data = System.Text.Encoding.UTF8.GetBytes(param);

            MemoryStream ms     = new MemoryStream();
            Stream       stream = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(ms);

            try
            {
                stream.Write(data, 0, data.Length);
            }
            finally
            {
                stream.Close();
                ms.Close();
            }
            return(Convert.ToBase64String(ms.ToArray()).Trim().Replace("+", "@"));
        }
コード例 #6
0
        public string Compress(string inputString)
        {
            // Create the zip stream
            System.IO.MemoryStream memstream = new System.IO.MemoryStream();
            ICSharpCode.SharpZipLib.GZip.GZipOutputStream zipstream = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(memstream);

            // Get the bytes of the input string
            Byte[] buffer = System.Text.Encoding.Unicode.GetBytes(inputString);

            // Write the bytes to the zipstream
            zipstream.Write(buffer, 0, buffer.Length);

            // Clean up
            zipstream.Close();
            memstream.Close();

            // Get the Base64 representation of the compressed string
            buffer = memstream.ToArray();
            string Result = Convert.ToBase64String(buffer);

            return(Result);
        }
コード例 #7
0
        public string Compress(string inputString)
        {
            // Create the zip stream
            System.IO.MemoryStream memstream = new System.IO.MemoryStream();
            ICSharpCode.SharpZipLib.GZip.GZipOutputStream zipstream = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(memstream);

            // Get the bytes of the input string
            Byte[] buffer = System.Text.Encoding.Unicode.GetBytes(inputString);

            // Write the bytes to the zipstream
            zipstream.Write(buffer, 0, buffer.Length);

            // Clean up
            zipstream.Close();
            memstream.Close();

            // Get the Base64 representation of the compressed string
            buffer = memstream.ToArray();
            string Result = Convert.ToBase64String(buffer);

            return Result;
        }