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


C# DeflateStream.Close方法代码示例

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


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

示例1: zlibDeflate

 public static void zlibDeflate(
     string pathInput,
     string pathOutput,
     CompressionMode mode,
     CompressionLevel level
 )
 {
     using (Stream input = File.OpenRead(pathInput))
     using (Stream output = File.Create(pathOutput))
     using (Stream deflateStream = new DeflateStream(
         mode == CompressionMode.Compress ? output : input,
         mode, level, true))
     {
         byte[] buff = new byte[ZLIB_BUFF_SIZE];
         int n = 0;
         Stream toRead = mode == CompressionMode.Compress ?
             input : deflateStream;
         Stream toWrite = mode == CompressionMode.Compress ?
             deflateStream : output;
         while (0 != (n = toRead.Read(buff, 0, buff.Length)))
         {
             toWrite.Write(buff, 0, n);
         }
         deflateStream.Close();
         input.Close();
         output.Close();
     }
 }
开发者ID:alejandro-varela,项目名称:AleNet,代码行数:28,代码来源:ZlibHelper.cs

示例2: CompressBuffer

 public static byte[] CompressBuffer(byte[] buffer)
 {
     byte[] compressed;
     using (var input = new MemoryStream(buffer))
     using (var compressStream = new MemoryStream())
     using (var compressor = new DeflateStream(compressStream, CompressionMode.Compress))
     {
         input.CopyTo(compressor);
         compressor.Close();
         compressed = compressStream.ToArray();
     }
     return compressed;
 }
开发者ID:Boblepointu,项目名称:Coob,代码行数:13,代码来源:ZlibHelper.cs

示例3: CompressBuffer

 public static byte[] CompressBuffer(byte[] buffer, ushort key, uint keyend)
 {
     byte[] compressed;
     using (var compressStream = new MemoryStream())
     using (var compressor = new DeflateStream(compressStream, CompressionMode.Compress))
     {
         compressor.Write(buffer, 0, buffer.Length);
         compressor.Close();
         compressed = compressStream.ToArray();
     }
     byte[] returnbytes = new byte[compressed.Length + 6];
     byte[] kbyte = BitConverter.GetBytes(key);
     byte[] kebyte = BitConverter.GetBytes(keyend);
     Array.Copy(kbyte, 0, returnbytes, 0, kbyte.Length);
     Array.Copy(compressed, 0, returnbytes, 2, compressed.Length);
     Array.Copy(kebyte, 0, returnbytes, returnbytes.Length - 4, kebyte.Length);
     return returnbytes;
 }
开发者ID:Wroud,项目名称:Coob,代码行数:18,代码来源:ZlibHelper.cs

示例4: Zlib_DisposedException_DeflateStream

        public void Zlib_DisposedException_DeflateStream()
        {
            string TextToCompress = LetMeDoItNow;

                MemoryStream ms1= new MemoryStream();

                Stream compressor= new DeflateStream(ms1, CompressionMode.Compress, false);

                TestContext.WriteLine("Text to compress is {0} bytes: '{1}'",
                                      TextToCompress.Length, TextToCompress);
                TestContext.WriteLine("using compressor: {0}", compressor.GetType().FullName);

                StreamWriter sw = new StreamWriter(compressor, Encoding.ASCII);
                sw.Write(TextToCompress);
                sw.Close(); // implicitly closes compressor
                sw.Close(); // implicitly closes compressor, again

                compressor.Close(); // explicitly closes compressor
                var a = ms1.ToArray();
                TestContext.WriteLine("Compressed stream is {0} bytes long", a.Length);

                var ms2 = new MemoryStream(a);
                Stream decompressor  = new DeflateStream(ms2, CompressionMode.Decompress, false);

                TestContext.WriteLine("using decompressor: {0}", decompressor.GetType().FullName);

                var sr = new StreamReader(decompressor, Encoding.ASCII);
                string DecompressedText = sr.ReadToEnd();
                sr.Close();

                TestContext.WriteLine("decompressor.CanRead = {0}",decompressor.CanRead);

                TestContext.WriteLine("Read {0} characters: '{1}'", DecompressedText.Length, DecompressedText);
                TestContext.WriteLine("\n");
                Assert.AreEqual<String>(TextToCompress, DecompressedText);

        }
开发者ID:bedashii,项目名称:ReturnMedz,代码行数:37,代码来源:ZlibUnitTest1.cs

示例5: DecompressTileBlock

		public static void DecompressTileBlock(byte[] buffer, int bufferStart, int bufferLength)
		{
			using (MemoryStream memoryStream = new MemoryStream())
			{
				memoryStream.Write(buffer, bufferStart, bufferLength);
				memoryStream.Position = 0L;
				bool flag = memoryStream.ReadByte() != 0;
				MemoryStream memoryStream3;
				if (flag)
				{
					MemoryStream memoryStream2 = new MemoryStream();
					using (DeflateStream deflateStream = new DeflateStream((Stream)memoryStream, CompressionMode.Decompress, CompressionLevel.BestCompression))
					{
						deflateStream.CopyTo(memoryStream2);
						deflateStream.Close();
					}
					memoryStream3 = memoryStream2;
					memoryStream3.Position = 0L;
				}
				else
				{
					memoryStream3 = memoryStream;
					memoryStream3.Position = 1L;
				}
				using (BinaryReader binaryReader = new BinaryReader(memoryStream3))
				{
					int xStart = binaryReader.ReadInt32();
					int yStart = binaryReader.ReadInt32();
					short width = binaryReader.ReadInt16();
					short height = binaryReader.ReadInt16();
					NetMessage.DecompressTileBlock_Inner(binaryReader, xStart, yStart, (int)width, (int)height);
				}
			}
		}
开发者ID:thegamingboffin,项目名称:Ulterraria_Reborn_GitHub,代码行数:34,代码来源:NetMessage.cs

示例6: CompressTileBlock

		public static int CompressTileBlock(int xStart, int yStart, short width, short height, byte[] buffer, int bufferStart)
		{
			int result;
			using (MemoryStream memoryStream = new MemoryStream())
			{
				using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
				{
					binaryWriter.Write(xStart);
					binaryWriter.Write(yStart);
					binaryWriter.Write(width);
					binaryWriter.Write(height);
					NetMessage.CompressTileBlock_Inner(binaryWriter, xStart, yStart, (int)width, (int)height);
					int num = buffer.Length;
					if ((long)bufferStart + memoryStream.Length > (long)num)
					{
						result = (int)((long)(num - bufferStart) + memoryStream.Length);
					}
					else
					{
						memoryStream.Position = 0L;
						MemoryStream memoryStream2 = new MemoryStream();
						using (DeflateStream deflateStream = new DeflateStream(memoryStream2, 0, true))
						{
							memoryStream.CopyTo(deflateStream);
							deflateStream.Flush();
							deflateStream.Close();
							deflateStream.Dispose();
						}
						if (memoryStream.Length <= memoryStream2.Length)
						{
							memoryStream.Position = 0L;
							buffer[bufferStart] = 0;
							bufferStart++;
							memoryStream.Read(buffer, bufferStart, (int)memoryStream.Length);
							result = (int)memoryStream.Length + 1;
						}
						else
						{
							memoryStream2.Position = 0L;
							buffer[bufferStart] = 1;
							bufferStart++;
							memoryStream2.Read(buffer, bufferStart, (int)memoryStream2.Length);
							result = (int)memoryStream2.Length + 1;
						}
					}
				}
			}
			return result;
		}
开发者ID:thegamingboffin,项目名称:Ulterraria_Reborn_GitHub,代码行数:49,代码来源:NetMessage.cs

示例7: Save

        public void Save(Stream Target,SaveFormatInfo Format,StreamProgress.ProgressFunction pfunction)
        {
            SerializationInfo sinfo;
            try
            {

                Stream outstream = Target;
                {
                    using (StreamProgress sp = new StreamProgress(outstream, pfunction))
                    {
                        if (Format is BinarySaveFormatInfo)
                        {
                            BinarySaveFormatInfo BinInfo = Format as BinarySaveFormatInfo;
                            //write out whether this is compressed.
                            IFormatter binformatter = BCBlockGameState.getFormatter<EditorSet>(BCBlockGameState.DataSaveFormats.Format_Binary);
                            outstream.WriteByte((byte)(BinInfo.CompressionType != CompressionTypeConstants.Compression_None ? 1 : 0));
                            Stream targetstream;
                            switch (BinInfo.CompressionType)
                            {
                            case CompressionTypeConstants.Compression_GZip:
                                targetstream = new GZipStream(outstream, CompressionMode.Compress);
                                break;
                            case CompressionTypeConstants.Compression_Deflate:
                                targetstream = new DeflateStream(outstream, CompressionMode.Compress, CompressionLevel.BestCompression);
                                break;
                            default:
                                targetstream = outstream;
                                break;
                            }
                            using (targetstream)
                            {
                                Cursor.Current = Cursors.WaitCursor;
                                binformatter.Serialize(targetstream, this);
                                targetstream.Close();
                                Cursor.Current = Cursors.Default;
                            }
                        }
                        else if(Format is XmlSaveFormatInfo)
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            //almost forgot to change this code to save to XML properly. the SOAP stuff, we have to remove at some stage...
                            XElement BuildElement = this.GetXmlData("EditorSet",null);
                            XDocument buildDocument = new XDocument(BuildElement);

                            buildDocument.Save(outstream,SaveOptions.OmitDuplicateNamespaces);

                            /*IFormatter xmlformat = BCBlockGameState.getFormatter<EditorSet>(BCBlockGameState.DataSaveFormats.Format_XML);
                            Cursor.Current = Cursors.WaitCursor;
                            xmlformat.Serialize(outstream,this);*/
                        }

                    }
                }

            }
            catch (Exception e)
            {
                Debug.Print("Exception in EditorSet.Save:" + e.ToString());

            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
开发者ID:BCProgramming,项目名称:BASeBlock,代码行数:65,代码来源:EditorSet.cs

示例8: decompress

        /*static void decompress()
        {
            decompress("C:/users/Luciano/Desktop/manifest.bin");
        }*/

        static void decompress(string inputfile, string outputPath)
        {
            FileStream f = File.Open(inputfile, FileMode.Open);
            FileStream final = File.Create(outputPath);

            StreamReader reader = new StreamReader(f);
            StreamWriter writer = new StreamWriter(final);

            DeflateStream a = new DeflateStream(f, CompressionMode.Decompress);

            int read = 0;
            byte[] buffer = new byte[1024 * 1024];

            f.Position = 10;

            while ((read = a.Read(buffer, 0, buffer.Length)) > 0)
            {
                final.Write(buffer, 0, read);
            }

            f.Close();
            a.Close();
            final.Close();
        }
开发者ID:luciano7,项目名称:aoeo,代码行数:29,代码来源:Program.cs

示例9: compress

        public static void compress()
        {
            FileStream f = File.Open("C:/users/Luciano/Desktop/manifest.txt", FileMode.Open, FileAccess.ReadWrite);
            FileStream final = File.Create("C:/users/Luciano/Desktop/manifest.bin");

            int size = (int)f.Length;

            StreamReader r = new StreamReader(f);
            BinaryWriter w = new BinaryWriter(final);

            w.Write("l33t".ToCharArray());
            w.Write(size);
            w.BaseStream.WriteByte(0x78);
            w.BaseStream.WriteByte(0x9C);

            DeflateStream a = new DeflateStream(f, CompressionMode.Compress);

            int read = 0;
            byte[] buffer = new byte[1024 * 1024];

            while ((read = a.Read(buffer, 0, buffer.Length)) > 0)
            {
                w.Write(buffer, 0, read);
            }

            a.Close();
            f.Close();
            

        }
开发者ID:luciano7,项目名称:aoeo,代码行数:30,代码来源:Program.cs


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