当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.Compression.GZipStream.Close方法代码示例

本文整理汇总了C#中System.IO.Compression.GZipStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.Compression.GZipStream.Close方法的具体用法?C# System.IO.Compression.GZipStream.Close怎么用?C# System.IO.Compression.GZipStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Compression.GZipStream的用法示例。


在下文中一共展示了System.IO.Compression.GZipStream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GZIP

        /// <summary>
        /// Compress contents to gzip
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static byte[] GZIP(ref byte[] input)
        {
            try
            {
                byte[] compressedData = null;
                MemoryStream oMemoryStream = null;
                System.IO.Compression.GZipStream compressedzipStream = null;
                oMemoryStream = new MemoryStream();
                compressedzipStream = new System.IO.Compression.GZipStream(oMemoryStream, System.IO.Compression.CompressionMode.Compress, false);
                compressedzipStream.Write(input, 0, input.Length);
                compressedzipStream.Close();
                compressedData = oMemoryStream.ToArray();
                compressedzipStream.Dispose();
                compressedzipStream.Close();
                oMemoryStream.Close();

                return compressedData;
            }
            catch (Exception ex)
            {

                return null;
            }
        }
开发者ID:phuongdesti,项目名称:color,代码行数:30,代码来源:Utility.cs

示例2: ZipCompress

        public static string ZipCompress(this string value)
        {
            //Transform string into byte[]  
            byte[] byteArray = new byte[value.Length];
            int indexBA = 0;
            foreach (char item in value.ToCharArray())
            {
                byteArray[indexBA++] = (byte)item;
            }

            //Prepare for compress
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.IO.Compression.GZipStream sw = new System.IO.Compression.GZipStream(ms,
                System.IO.Compression.CompressionMode.Compress);

            //Compress
            sw.Write(byteArray, 0, byteArray.Length);
            //Close, DO NOT FLUSH cause bytes will go missing...
            sw.Close();

            //Transform byte[] zip data to string
            byteArray = ms.ToArray();
            System.Text.StringBuilder sB = new System.Text.StringBuilder(byteArray.Length);
            foreach (byte item in byteArray)
            {
                sB.Append((char)item);
            }
            ms.Close();
            sw.Dispose();
            ms.Dispose();
            return sB.ToString();
        }
开发者ID:Cyberbanan,项目名称:voxeliq,代码行数:32,代码来源:StringExtensions.cs

示例3: UnZip

        public static string UnZip(string value)
        {
            //Transform string into byte[]
            byte[] byteArray = new byte[value.Length];
            int indexBA = 0;
            foreach (char item in value.ToCharArray())
            {
                byteArray[indexBA++] = (byte)item;
            }

            //Prepare for decompress
            System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArray);
            System.IO.Compression.GZipStream sr = new System.IO.Compression.GZipStream(ms,
                System.IO.Compression.CompressionMode.Decompress);

            //Reset variable to collect uncompressed result
            byteArray = new byte[byteArray.Length];

            //Decompress
            int rByte = sr.Read(byteArray, 0, byteArray.Length);

            //Transform byte[] unzip data to string
            System.Text.StringBuilder sB = new System.Text.StringBuilder(rByte);
            //Read the number of bytes GZipStream red and do not a for each bytes in
            //resultByteArray;
            for (int i = 0; i < rByte; i++)
            {
                sB.Append((char)byteArray[i]);
            }
            sr.Close();
            ms.Close();
            sr.Dispose();
            ms.Dispose();
            return sB.ToString();
        }
开发者ID:yuechuanbingzhi163,项目名称:myhistoryprojects,代码行数:35,代码来源:WebPost.cs

示例4: GZip_Decompress

        /// <summary>
        /// In Memory GZip Decompressor 
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] GZip_Decompress(this byte[] data)
        {
            int length = 100000; //10Kb
            byte[] Ob = new byte[length];
            byte[] result = null;

            using (var ms = new MemoryStream(data))
            {
                using (var gz = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress))
                {
                    int a = 0;
                    while ((a = gz.Read(Ob, 0, length)) > 0)
                    {
                        if (a == length)
                            result = result.Concat(Ob);
                        else
                            result = result.Concat(Ob.Substring(0, a));
                    }
                    gz.Close();
                }
                ms.Close();
            }

            return result;
        }
开发者ID:hhblaze,项目名称:DBreeze,代码行数:30,代码来源:Compression.cs

示例5: CompressOrDecompressFile

        /// <summary>
        /// Компрессия или декомпрессия файла
        /// </summary>
        /// <param name="fromFile">Исходный файл для компрессии или декомпрессии</param>
        /// <param name="toFile">Целевой файл</param>
        /// <param name="compressionMode">Указывает на компрессию или декомпрессию</param>
        private static void CompressOrDecompressFile(string fromFile, string toFile, System.IO.Compression.CompressionMode compressionMode)
        {
            System.IO.FileStream toFs = null;
            System.IO.Compression.GZipStream gzStream = null;
            System.IO.FileStream fromFs = new System.IO.FileStream(fromFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            try
            {
                toFs = new System.IO.FileStream(toFile, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                gzStream = new System.IO.Compression.GZipStream(toFs, compressionMode);
                byte[] buf = new byte[fromFs.Length];
                fromFs.Read(buf, 0, buf.Length);
                gzStream.Write(buf, 0, buf.Length);
            }
            finally
            {
                if (gzStream != null)
                    gzStream.Close();

                if (toFs != null)
                    toFs.Close();

                fromFs.Close();
            }
        }
开发者ID:UGTU,项目名称:UGTUKadrProject,代码行数:31,代码来源:CompressionHelper.cs

示例6: CompressGZIP

 /// <summary>
 /// This function return a byte array compressed by GZIP algorithm.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] CompressGZIP(byte[] data)
 {
     System.IO.MemoryStream streamoutput = new System.IO.MemoryStream();
     System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(streamoutput, System.IO.Compression.CompressionMode.Compress, false);
     gzip.Write(data, 0, data.Length);
     gzip.Close();
     return streamoutput.ToArray();
 }
开发者ID:krishkhan,项目名称:Prototype,代码行数:13,代码来源:httphelper.cs

示例7: CompressGZip

        /// <summary>
        /// In Memory Compression with Gzip
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] CompressGZip(this byte[] data)
        {
            byte[] res = null;
            MemoryStream ms = null;
            System.IO.Compression.GZipStream gz = null;

            try
            {
                using (ms = new MemoryStream())
                {
                    using (gz = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress, false))
                    {
                        gz.Write(data, 0, data.Length);
                        gz.Close();
                    }

                    res = ms.ToArray();

                }
            }
            catch
            {
                res = null;
            }
            finally
            {
                if (gz != null)
                {
                    gz.Close();
                    gz.Dispose();
                }
                if (ms != null)
                {
                    ms.Close();
                    ms.Dispose();
                }
            }

            return res;
        }
开发者ID:enginekit,项目名称:DBreezeBased,代码行数:45,代码来源:GzipCompressor.cs

示例8: compress

        public byte[] compress(byte[] data)
        {
            MemoryStream packed = new MemoryStream();

            System.IO.Stream packer = new System.IO.Compression.GZipStream(
                packed,
                System.IO.Compression.CompressionMode.Compress
            );

            packer.Write(data, 0, data.Length);
            packer.Close();

            return packed.ToArray();
        }
开发者ID:begoon,项目名称:stuff,代码行数:14,代码来源:compressor.cs

示例9: start

        private void start()
        {
            //Debug.Assert(MAPSIZE == 64, "The BlockBulkTransfer message requires a map size of 64.");

            for (byte x = 0; x < MAPSIZE; x++)
                for (byte y = 0; y < MAPSIZE; y += 16)
                {
                    NetBuffer msgBuffer = infsN.CreateBuffer();
                    msgBuffer.Write((byte)Infiniminer.InfiniminerMessage.BlockBulkTransfer);
                    if (!compression)
                    {
                        msgBuffer.Write(x);
                        msgBuffer.Write(y);
                        for (byte dy = 0; dy < 16; dy++)
                            for (byte z = 0; z < MAPSIZE; z++)
                                msgBuffer.Write((byte)(infs.blockList[x, y + dy, z]));
                        if (client.Status == NetConnectionStatus.Connected)
                            infsN.SendMessage(msgBuffer, client, NetChannel.ReliableUnordered);
                    }
                    else
                    {
                        //Compress the data so we don't use as much bandwith - Xeio's work
                        var compressedstream = new System.IO.MemoryStream();
                        var uncompressed = new System.IO.MemoryStream();
                        var compresser = new System.IO.Compression.GZipStream(compressedstream, System.IO.Compression.CompressionMode.Compress);

                        //Send a byte indicating that yes, this is compressed
                        msgBuffer.Write((byte)255);

                        //Write everything we want to compress to the uncompressed stream
                        uncompressed.WriteByte(x);
                        uncompressed.WriteByte(y);

                        for (byte dy = 0; dy < 16; dy++)
                            for (byte z = 0; z < MAPSIZE; z++)
                                uncompressed.WriteByte((byte)(infs.blockList[x, y + dy, z]));

                        //Compress the input
                        compresser.Write(uncompressed.ToArray(), 0, (int)uncompressed.Length);
                        //infs.ConsoleWrite("Sending compressed map block, before: " + uncompressed.Length + ", after: " + compressedstream.Length);
                        compresser.Close();

                        //Send the compressed data
                        msgBuffer.Write(compressedstream.ToArray());
                        if (client.Status == NetConnectionStatus.Connected)
                            infsN.SendMessage(msgBuffer, client, NetChannel.ReliableUnordered);
                    }
                }
            conn.Abort();
        }
开发者ID:GlennSandoval,项目名称:Infiniminer,代码行数:50,代码来源:MapSender.cs

示例10: perror

        public static string lerror = ""; // Gets the last error that occurred in this struct. Similar to the C perror().

        #endregion Fields

        #region Methods

        public static bool compress(string infile, string outfile)
        {
            try {
                byte[] ifdata = System.IO.File.ReadAllBytes(infile);
                System.IO.StreamWriter sw = new System.IO.StreamWriter(outfile);
                System.IO.Compression.GZipStream gzs = new System.IO.Compression.GZipStream(sw.BaseStream, System.IO.Compression.CompressionMode.Compress);
                gzs.Write(ifdata, 0, ifdata.Length);
                gzs.Close();
                gzs.Dispose();
            } catch (System.Exception ex) {
                lerror = ex.Message;
                return false;
            }
            return true;
        }
开发者ID:nastys,项目名称:Uwizard,代码行数:21,代码来源:GZip.cs

示例11: GZIP

 /// <summary>
 /// Compress contents to gzip
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 /// <remarks></remarks>
 public static byte[] GZIP(ref string s)
 {
     byte[] buffer = null;
     byte[] compressedData = null;
     MemoryStream oMemoryStream = null;
     System.IO.Compression.GZipStream compressedzipStream = null;
     oMemoryStream = new MemoryStream();
     buffer = System.Text.Encoding.UTF8.GetBytes(s);
     compressedzipStream = new System.IO.Compression.GZipStream(oMemoryStream, System.IO.Compression.CompressionMode.Compress, true);
     compressedzipStream.Write(buffer, 0, buffer.Length);
     compressedzipStream.Dispose();
     compressedzipStream.Close();
     compressedData = oMemoryStream.ToArray();
     oMemoryStream.Close();
     return compressedData;
 }
开发者ID:phuongnt,项目名称:testmvc,代码行数:22,代码来源:Utility.cs

示例12: CompressDataSet

        /// <summary>
        /// DataSet���л���ѹ��
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        public static byte[] CompressDataSet(DataSet ds)
        {
            byte[] compressedBuf;

            #region serialize
            RawSerializer rs = new RawSerializer();
            byte[] buf = rs.Serialize(ds);
            #endregion

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.IO.Compression.GZipStream gs = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress, true);

            gs.Write(buf, 0, buf.Length);
            gs.Close();

            compressedBuf = ms.ToArray();

            return compressedBuf;
        }
开发者ID:ud223,项目名称:jx,代码行数:24,代码来源:CompressionSerialize.cs

示例13: Compress

        /// <summary>
        /// �������л���ѹ��
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        public static byte[] Compress(object obj, Type type)
        {
            byte[] compressedBuf;
            CompressionSerialize compressionSerialize = new CompressionSerialize();

            #region serialize
            byte[] buf = compressionSerialize.Serialize(obj, type);
            #endregion

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.IO.Compression.GZipStream gs = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress, true);

            gs.Write(buf, 0, buf.Length);
            gs.Close();

            compressedBuf = ms.ToArray();

            return compressedBuf;
        }
开发者ID:ud223,项目名称:jx,代码行数:24,代码来源:CompressionSerialize.cs

示例14: Compress

        // <summary>
        /// 对byte数组进行压缩  
        /// </summary>  
        /// <param name="data">待压缩的byte数组</param>  
        /// <returns>压缩后的byte数组</returns>  
        public static byte[] Compress(byte[] data)
        {
            try
            {
                MemoryStream ms = new MemoryStream();
                System.IO.Compression.GZipStream zip = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress, true);
                zip.Write(data, 0, data.Length);
                zip.Close();
                byte[] buffer = new byte[ms.Length];
                ms.Position = 0;
                ms.Read(buffer, 0, buffer.Length);
                ms.Close();
                return buffer;

            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
开发者ID:ZixiangBoy,项目名称:FAS,代码行数:25,代码来源:Program.cs

示例15: GZip_Compress

        /// <summary>
        /// In Memory Compression with Gzip
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] GZip_Compress(this byte[] data)
        {
            byte[] res = null;
            MemoryStream ms = null;
            System.IO.Compression.GZipStream gz = null;

            using (ms = new MemoryStream())
            {
                using (gz = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress, false))
                {
                    gz.Write(data, 0, data.Length);
                    gz.Close();
                }

                res = ms.ToArray();
                ms.Close();
            }

            return res;
        }
开发者ID:hhblaze,项目名称:DBreeze,代码行数:25,代码来源:Compression.cs


注:本文中的System.IO.Compression.GZipStream.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。