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


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

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


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

示例5: 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

示例6: decompress

 public static bool decompress(string infile, string outfile)
 {
     try {
         System.IO.StreamWriter sw = new System.IO.StreamWriter(outfile);
         System.IO.StreamReader sr = new System.IO.StreamReader(infile);
         System.IO.Compression.GZipStream gzs = new System.IO.Compression.GZipStream(sr.BaseStream, System.IO.Compression.CompressionMode.Decompress);
         int lbyte = gzs.ReadByte();
         while (lbyte != -1) {
             sw.BaseStream.WriteByte((byte) lbyte);
             lbyte = gzs.ReadByte();
         }
         gzs.Close();
         gzs.Dispose();
         sw.Close();
         sw.Dispose();
     } catch (System.Exception ex) {
         lerror = ex.Message;
         return false;
     }
     return true;
 }
开发者ID:nastys,项目名称:Uwizard,代码行数:21,代码来源:GZip.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: accept

        public void accept(string txtName)
        {
            textName = txtName;
            string type = Request.ContentType;
            int separator = type.IndexOf("/");
            string compressionFormat = type.Substring(separator+1);

            int len = txtName.Length;

            //compress
            byte[] stringToByte=new byte[len+1];
            int byteIndex=0;
            foreach(char c in txtName.ToCharArray())
            {
                stringToByte[byteIndex++] = (byte)c;
            }
            var bytes = Encoding.ASCII.GetBytes(txtName);

            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
            System.IO.Compression.GZipStream gzipStream = new System.IO.Compression.GZipStream(memoryStream,System.IO.Compression.CompressionMode.Compress);

            gzipStream.Write(bytes,0,bytes.Length);
            gzipStream.Close();

            stringToByte = memoryStream.ToArray();

            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(stringToByte.Length);
            foreach(byte b in stringToByte)
            {
                stringBuilder.Append((char)b);
            }
            memoryStream.Close();
            gzipStream.Dispose();
            memoryStream.Dispose();

            string s = stringBuilder.ToString();

            //Decompress
            byte[] decompressStream=new byte[s.Length];
            byteIndex=0;
            foreach(char c in s.ToCharArray())
            {
                decompressStream[byteIndex++]=(byte)c;
            }

            System.IO.MemoryStream ms = new System.IO.MemoryStream(decompressStream);
            System.IO.Compression.GZipStream gs = new System.IO.Compression.GZipStream(ms,System.IO.Compression.CompressionMode.Decompress);

            int byteRead = gs.Read(decompressStream,0,decompressStream.Length);

            System.Text.StringBuilder builder = new System.Text.StringBuilder(byteRead);
             foreach(byte b in decompressStream)
             {
                 builder.Append((char)b);
             }

             ms.Close();
             gs.Close();
             ms.Dispose();
             gs.Dispose();

             String str = builder.ToString();
             int a = 0;
        }
开发者ID:abhi717099,项目名称:defaultWebsite,代码行数:64,代码来源:HomeController.cs

示例9: StopCore

		void StopCore(string msg)
		{
			coredead = true;
			Console.WriteLine("Core stopped.");
			for (int i = 0; i < soundbuffer.Length; i++)
				soundbuffer[i] = 0;

			var gz = new System.IO.Compression.GZipStream(
				new MemoryStream(Convert.FromBase64String(dispfont), false),
				System.IO.Compression.CompressionMode.Decompress);
			byte[] font = new byte[2048];
			gz.Read(font, 0, 2048);
			gz.Dispose();
			
			// cores aren't supposed to have bad dependencies like System.Drawing, right?

			int scx = 0;
			int scy = 0;

			foreach (char c in msg)
			{
				if (scx == 240 || c == '\n')
				{
					scy += 8;
					scx = 0;
				}
				if (scy == 160)
					break;
				if (c == '\r' || c == '\n')
					continue;
				if (c < 256 && c != ' ')
				{
					int fpos = c * 8;
					for (int j = 0; j < 8; j++)
					{
						for (int i = 0; i < 8; i++)
						{
							if ((font[fpos] >> i & 1) != 0)
								videobuffer[(scy + j) * 240 + scx + i] = unchecked((int)0xffff0000);
							else
								videobuffer[(scy + j) * 240 + scx + i] = unchecked((int)0xff000000);
						}
						fpos++;
					}
				}
				scx += 8;
			}
		}
开发者ID:rjb8682,项目名称:BizHawk-1,代码行数:48,代码来源:Meteor.cs

示例10: UnGZIP

        public static string UnGZIP(ref byte[] input)
        {
            System.IO.MemoryStream oMemoryStream = null;
            System.IO.Compression.GZipStream oGZipStream = null;
            int iLength = 0;
            byte[] byteArray = new byte[100001];
            System.Text.StringBuilder oStringBuilder = new System.Text.StringBuilder();

            oMemoryStream = new System.IO.MemoryStream(input);
            oGZipStream = new System.IO.Compression.GZipStream(oMemoryStream, System.IO.Compression.CompressionMode.Decompress);
            oMemoryStream.Flush();
            oGZipStream.Flush();
            do
            {
                iLength = oGZipStream.Read(byteArray, 0, byteArray.Length);
                if (iLength < 1)
                    break; // TODO: might not be correct. Was : Exit Do
                oStringBuilder.Append(System.Text.Encoding.UTF8.GetString(byteArray, 0, iLength));
            } while (true);
            oGZipStream.Close();
            oMemoryStream.Close();
            oGZipStream.Dispose();
            oMemoryStream.Dispose();
            return oStringBuilder.ToString();
        }
开发者ID:phuongdesti,项目名称:color,代码行数:25,代码来源:Utility.cs

示例11: Zlib_GZipStream_FileName_And_Comments

        public void Zlib_GZipStream_FileName_And_Comments()
        {
            // select the name of the zip file
            string FileToCompress = System.IO.Path.Combine(TopLevelDir, "Zlib_GZipStream.dat");
            Assert.IsFalse(System.IO.File.Exists(FileToCompress), "The temporary zip file '{0}' already exists.", FileToCompress);
            byte[] working = new byte[WORKING_BUFFER_SIZE];
            int n = -1;

            int sz = this.rnd.Next(21000) + 15000;
            TestContext.WriteLine("  Creating file: {0} sz({1})", FileToCompress, sz);
            CreateAndFillFileText(FileToCompress, sz);

            System.IO.FileInfo fi1 = new System.IO.FileInfo(FileToCompress);
            int crc1 = DoCrc(FileToCompress);

            // four trials, all combos of FileName and Comment null or not null.
            for (int k = 0; k < 4; k++)
            {
                string CompressedFile = String.Format("{0}-{1}.compressed", FileToCompress, k);

                using (Stream input = File.OpenRead(FileToCompress))
                {
                    using (FileStream raw = new FileStream(CompressedFile, FileMode.Create))
                    {
                        using (GZipStream compressor =
                               new GZipStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression, true))
                        {
                            // FileName is optional metadata in the GZip bytestream
                            if (k % 2 == 1)
                                compressor.FileName = FileToCompress;

                            // Comment is optional metadata in the GZip bytestream
                            if (k > 2)
                                compressor.Comment = "Compressing: " + FileToCompress;

                            byte[] buffer = new byte[1024];
                            n = -1;
                            while (n != 0)
                            {
                                if (n > 0)
                                    compressor.Write(buffer, 0, n);

                                n = input.Read(buffer, 0, buffer.Length);
                            }
                        }
                    }
                }

                System.IO.FileInfo fi2 = new System.IO.FileInfo(CompressedFile);

                Assert.IsTrue(fi1.Length > fi2.Length, String.Format("Compressed File is not smaller, trial {0} ({1}!>{2})", k, fi1.Length, fi2.Length));


                // decompress twice:
                // once with System.IO.Compression.GZipStream and once with Alienlab.Zlib.GZipStream
                for (int j = 0; j < 2; j++)
                {
                    using (var input = System.IO.File.OpenRead(CompressedFile))
                    {

                        Stream decompressor = null;
                        try
                        {
                            switch (j)
                            {
                                case 0:
                                    decompressor = new Alienlab.Zlib.GZipStream(input, CompressionMode.Decompress, true);
                                    break;
                                case 1:
                                    decompressor = new System.IO.Compression.GZipStream(input, System.IO.Compression.CompressionMode.Decompress, true);
                                    break;
                            }

                            string DecompressedFile =
                                                        String.Format("{0}.{1}.decompressed", CompressedFile, (j == 0) ? "Ionic" : "BCL");

                            TestContext.WriteLine("........{0} ...", System.IO.Path.GetFileName(DecompressedFile));

                            using (var s2 = System.IO.File.Create(DecompressedFile))
                            {
                                n = -1;
                                while (n != 0)
                                {
                                    n = decompressor.Read(working, 0, working.Length);
                                    if (n > 0)
                                        s2.Write(working, 0, n);
                                }
                            }

                            int crc2 = DoCrc(DecompressedFile);
                            Assert.AreEqual<Int32>(crc1, crc2);

                        }
                        finally
                        {
                            if (decompressor != null)
                                decompressor.Dispose();
                        }
                    }
                }
//.........这里部分代码省略.........
开发者ID:alienlab,项目名称:Alienlab.Zip.Reduced,代码行数:101,代码来源:ZlibUnitTest1.cs

示例12: Decompress

        private void Decompress()
        {
            if (this._Compressed.Length == 0)
            {
                this._UnCompressed = string.Empty;
                return;
            }

            string Result = string.Empty;

            try
            {
                byte[] ZippedData = null;

                //Convert the compressed string into a byte array and decrypt the array if required
                if (this._Passphrase.Length > 0)
                {
                    ZippedData = Decrypt(System.Convert.FromBase64String(this._Compressed));
                }
                else
                {
                    ZippedData = System.Convert.FromBase64String(this._Compressed);
                }

                //Decompress the byte array
                System.IO.MemoryStream objMemStream = new System.IO.MemoryStream(ZippedData);
                System.IO.Compression.GZipStream objGZipStream = new System.IO.Compression.GZipStream(objMemStream, System.IO.Compression.CompressionMode.Decompress);
                byte[] sizeBytes = new byte[4];

                objMemStream.Position = objMemStream.Length - 4;
                objMemStream.Read(sizeBytes, 0, 4);

                int iOutputSize = BitConverter.ToInt32(sizeBytes, 0);

                objMemStream.Position = 0;

                byte[] UnZippedData = new byte[iOutputSize];

                objGZipStream.Read(UnZippedData, 0, iOutputSize);

                objGZipStream.Dispose();
                objMemStream.Dispose();

                //Convert the decompressed byte array back to a string
                Result = this._TextEncoding.GetString(UnZippedData);

            }
            catch (Exception)
            {
            }
            finally
            {
                this._UnCompressed = Result;
            }
        }
开发者ID:sandeeplocality,项目名称:UG12Server,代码行数:55,代码来源:CompressString.cs

示例13: Compress

        private void Compress()
        {
            if (this._UnCompressed.Length == 0)
            {
                this._Compressed = string.Empty;
                return;
            }

            string Result = string.Empty;

            try
            {
                //Convert the uncompressed string into a byte array
                byte[] UnZippedData = this._TextEncoding.GetBytes(this._UnCompressed);

                //Compress the byte array
                System.IO.MemoryStream MS = new System.IO.MemoryStream();
                System.IO.Compression.GZipStream GZip = new System.IO.Compression.GZipStream(MS, System.IO.Compression.CompressionMode.Compress);
                GZip.Write(UnZippedData, 0, UnZippedData.Length);
                //Don't FLUSH here - it possibly leads to data loss!
                GZip.Close();

                byte[] ZippedData = null;

                //Encrypt the compressed byte array, if required
                if (this._Passphrase.Length > 0)
                {
                    ZippedData = Encrypt(MS.ToArray());
                }
                else
                {
                    ZippedData = MS.ToArray();
                }

                //Convert the compressed byte array back to a string
                Result = System.Convert.ToBase64String(ZippedData);

                MS.Close();
                GZip.Dispose();
                MS.Dispose();
            }
            catch (Exception)
            {
                //Keep quiet - in case of an exception an empty string is returned
            }
            finally
            {
                this._Compressed = Result;
            }
        }
开发者ID:sandeeplocality,项目名称:UG12Server,代码行数:50,代码来源:CompressString.cs

示例14: DecompressGZip

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

            MemoryStream ms = null;
            System.IO.Compression.GZipStream gz = null;

            try
            {
                using (ms = new MemoryStream(data))
                {
                    using (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 = Concat(result, Ob);
                                result = result.Concat(Ob);
                            else
                                //result = Concat(result, Substring(Ob, 0, a));
                                result = result.Concat(Ob.Substring(0, a));
                        }
                    }
                }
            }
            catch
            {
                result = null;
            }
            finally
            {
                if (gz != null)
                {
                    gz.Close();
                    gz.Dispose();
                }
                if (ms != null)
                {
                    ms.Close();
                    ms.Dispose();
                }
            }

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


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