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


C# DeflateStream.CopyTo方法代码示例

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


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

示例1: Decompress

		/// <summary>
		/// Returns decompressed version of given string.
		/// </summary>
		/// <param name="str"></param>
		/// <returns></returns>
		public static string Decompress(string str)
		{
			if (str.Length < 12) // zlib header + checksum
				throw new InvalidDataException("Compressed data seems too short.");

			// Strip length and zlib header
			var pos = str.IndexOf(';');
			if (pos == -1)
				pos = str.IndexOf("S");
			str = str.Substring((pos > -1 ? 4 + pos + 1 : 4));

			// Hex string to byte array
			int len = str.Length;
			var barr = new byte[len >> 1];
			for (int i = 0; i < len; i += 2)
				barr[i >> 1] = Convert.ToByte(str.Substring(i, 2), 16);

			// Decompress and return
			using (var mout = new MemoryStream())
			using (var min = new MemoryStream(barr))
			using (var df = new DeflateStream(min, CompressionMode.Decompress))
			{
				df.CopyTo(mout);
				return Encoding.Unicode.GetString(mout.ToArray());
			}
		}
开发者ID:xKamuna,项目名称:aura,代码行数:31,代码来源:MabiZip.cs

示例2: WebSocket

		public WebSocket(DiscordWSClient client)
		{
			_client = client;
			_logLevel = client.Config.LogLevel;

			_loginTimeout = client.Config.ConnectionTimeout;
			_cancelToken = new CancellationToken(true);
			_connectedEvent = new ManualResetEventSlim(false);
			
			_engine = new WebSocketSharpEngine(this, client.Config);
			_engine.BinaryMessage += (s, e) =>
			{
				using (var compressed = new MemoryStream(e.Data, 2, e.Data.Length - 2))
				using (var decompressed = new MemoryStream())
				{
					using (var zlib = new DeflateStream(compressed, CompressionMode.Decompress))
						zlib.CopyTo(decompressed);
					decompressed.Position = 0;
                    using (var reader = new StreamReader(decompressed))
						ProcessMessage(reader.ReadToEnd()).Wait();
				}
            };
			_engine.TextMessage += (s, e) =>
			{
				/*await*/ ProcessMessage(e.Message).Wait();
			};
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:27,代码来源:WebSocket.cs

示例3: WebSocket

		public WebSocket(DiscordClient client, JsonSerializer serializer, Logger logger)
		{
            _client = client;
            Logger = logger;
            _serializer = serializer;

            _lock = new AsyncLock();
            _taskManager = new TaskManager(Cleanup);
            CancelToken = new CancellationToken(true);
			_connectedEvent = new ManualResetEventSlim(false);

#if !DOTNET5_4
			_engine = new WS4NetEngine(client.Config, _taskManager);
#else
			_engine = new BuiltInEngine(client.Config);
#endif
            _engine.BinaryMessage += (s, e) =>
            {
	            using (var compressed = new MemoryStream(e.Data, 2, e.Data.Length - 2))
	            using (var decompressed = new MemoryStream())
	            {
		            using (var zlib = new DeflateStream(compressed, CompressionMode.Decompress))
			            zlib.CopyTo(decompressed);
		            decompressed.Position = 0;
                    using (var reader = new StreamReader(decompressed))
			            ProcessMessage(reader.ReadToEnd()).GetAwaiter().GetResult();
	            }
            };
			_engine.TextMessage += (s, e) => ProcessMessage(e.Message).Wait(); 
		}
开发者ID:MarlboroTX,项目名称:Discord.Net,代码行数:30,代码来源:WebSocket.cs

示例4: Unbind

        public override UnbindResult Unbind(HttpRequestData request, IOptions options)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var payload = Convert.FromBase64String(request.QueryString["SAMLRequest"].First());
            using (var compressed = new MemoryStream(payload))
            {
                using (var decompressedStream = new DeflateStream(compressed, CompressionMode.Decompress, true))
                {
                    using (var deCompressed = new MemoryStream())
                    {
                        decompressedStream.CopyTo(deCompressed);

                        var xml = new XmlDocument()
                        {
                            PreserveWhitespace = true
                        };

                        xml.LoadXml(Encoding.UTF8.GetString(deCompressed.GetBuffer()));

                        return new UnbindResult(
                            xml.DocumentElement,
                            request.QueryString["RelayState"].SingleOrDefault());
                    }
                }
            }
        }
开发者ID:feng-jing,项目名称:authservices,代码行数:30,代码来源:Saml2RedirectBinding.cs

示例5: FromId

 // Methods
 public static Map FromId(int id)
 {
     lock (MapsManager.CheckLock)
     {
         if (MapsManager.MapId_Map.ContainsKey(id))
         {
             return MapsManager.MapId_Map[id];
         }
         string str = ((id % 10).ToString() + "/" + id.ToString() + ".dlm");
         if (MapsManager.D2pFileManager.MapExists(str))
         {
             MemoryStream stream = new MemoryStream(MapsManager.D2pFileManager.method_1(str)) { Position = 2 };
             DeflateStream stream2 = new DeflateStream(stream, CompressionMode.Decompress);
             byte[] buffer = new byte[50001];
             MemoryStream destination = new MemoryStream(buffer);
             stream2.CopyTo(destination);
             destination.Position = 0;
             BigEndianReader reader = new BigEndianReader(destination);
             Map map2 = new Map();
             map2.Init(reader);
             MapsManager.MapId_Map.Add(id, map2);
             if ((MapsManager.MapId_Map.Count > 1000))
             {
                 MapsManager.MapId_Map.Remove(MapsManager.MapId_Map.Keys.First());
             }
             return map2;
         }
         MapsManager.MapId_Map.Add(id, null);
         if ((MapsManager.MapId_Map.Count > 1000))
         {
             MapsManager.MapId_Map.Remove(MapsManager.MapId_Map.Keys.First());
         }
         return null;
     }
 }
开发者ID:DjTrilogic,项目名称:BlueSheep,代码行数:36,代码来源:MapsManager.cs

示例6: LoadAddonInfoData

        public static void LoadAddonInfoData(RealmSession session, byte[] packedData, int packedSize, int unpackedSize)
        {
            // Check ZLib header (normal mode)
            if (packedData[0] == 0x78 && packedData[1] == 0x9C)
            {
                var unpackedAddonData = new byte[unpackedSize];

                if (packedSize > 0)
                {
                    using (var inflate = new DeflateStream(new MemoryStream(packedData, 2, packedSize - 6), CompressionMode.Decompress))
                    {
                        var decompressed = new MemoryStream();
                        inflate.CopyTo(decompressed);

                        decompressed.Seek(0, SeekOrigin.Begin);

                        for (int i = 0; i < unpackedSize; i++)
                            unpackedAddonData[i] = (byte)decompressed.ReadByte();
                    }
                }

                HandleAddonInfo(session, unpackedAddonData);
            }
            else
            {
                Log.Message(LogType.Error, "Wrong AddonInfo for Client '{0}'.", session.GetClientIP());

                session.Dispose();
            }
        }
开发者ID:4jb,项目名称:Arctium-WoD-Sandbox,代码行数:30,代码来源:AddonHandler.cs

示例7: GetAddonInfoData

        public static byte[] GetAddonInfoData(CharacterSession session, byte[] packedData, int packedSize, int unpackedSize)
        {
            // Check ZLib header (normal mode)
            if (packedData[0] == 0x78 && packedData[1] == 0x9C)
            {
                var unpackedAddonData = new byte[unpackedSize];

                if (packedSize > 0)
                {
                    using (var inflate = new DeflateStream(new MemoryStream(packedData, 2, packedSize - 6), CompressionMode.Decompress))
                    {
                        var decompressed = new MemoryStream();
                        inflate.CopyTo(decompressed);

                        decompressed.Seek(0, SeekOrigin.Begin);

                        for (int i = 0; i < unpackedSize; i++)
                            unpackedAddonData[i] = (byte)decompressed.ReadByte();
                    }
                }

                return unpackedAddonData;
            }
            else
            {
                Log.Error($"Wrong AddonInfo for Client '{session.GetClientInfo()}'.");

                session.Dispose();
            }

            return null;
        }
开发者ID:GlassFace,项目名称:Arctium-WoW,代码行数:32,代码来源:AddonHandler.cs

示例8: Decode

 /// <summary>
 /// Decode the content
 /// </summary>
 /// <param name="data">Content to decode</param>
 /// <returns>Decoded content</returns>
 public byte[] Decode(byte[] data)
 {
     var output = new MemoryStream();
     var input = new MemoryStream(data);
     using (var stream = new DeflateStream(input, CompressionMode.Decompress))
         stream.CopyTo(output);
     return output.ToArray();
 }
开发者ID:chesiq,项目名称:restsharp.portable,代码行数:13,代码来源:DeflateEncoding.cs

示例9: Decompress

 /// <summary>
 /// Decompresses the specified input.
 /// </summary>
 /// <param name="input">The input.</param>
 /// <returns>The decompressed data.</returns>
 public static byte[] Decompress(this byte[] input)
 {
     var inflatedStream = new MemoryStream(input);
     var outputStream = new MemoryStream();
     var decompressor = new DeflateStream(inflatedStream, CompressionMode.Decompress);
     decompressor.CopyTo(outputStream);
     decompressor.Close();
     return outputStream.ToArray();
 }
开发者ID:Celderon,项目名称:oxyplot,代码行数:14,代码来源:DeflateStreamExtensions.cs

示例10: DecompressData

        public static byte[] DecompressData(byte[] data)
        {
            MemoryStream ms = new MemoryStream();
            MemoryStream stream = new MemoryStream(data, 2, data.Length - 2);
            DeflateStream s = new DeflateStream(stream, CompressionMode.Decompress);
            s.CopyTo(ms);
            return ms.ToArray();

        }
开发者ID:Stricted,项目名称:SPHDecode,代码行数:9,代码来源:Zlib.cs

示例11: Decompress

 /// <summary>解压缩数据流</summary>
 /// <param name="inStream">输入流</param>
 /// <param name="outStream">输出流</param>
 public static void Decompress(this Stream inStream, Stream outStream)
 {
     // 第三个参数为true,保持数据流打开,内部不应该干涉外部,不要关闭外部的数据流
     using (Stream stream = new DeflateStream(inStream, CompressionMode.Decompress, true))
     {
         stream.CopyTo(outStream);
         stream.Close();
     }
 }
开发者ID:g992com,项目名称:esb,代码行数:12,代码来源:IOHelper.cs

示例12: Decompress

 /// <summary>
 /// Decompresses the given data.
 /// </summary>
 /// <param name="data">The data to decompress.</param>
 /// <returns>The decompressed version of the data.</returns>
 public static byte[] Decompress(byte[] data)
 {
     using (var streamData = new MemoryStream(data))
     using (var streamDecompressed = new MemoryStream())
     using (var deflate = new DeflateStream(streamData, CompressionMode.Decompress))
     {
         deflate.CopyTo(streamDecompressed);
         return streamDecompressed.ToArray();
     }
 }
开发者ID:broccliman,项目名称:Presentation.WCF,代码行数:15,代码来源:DataUtility.cs

示例13: Decompress

 public byte[] Decompress(byte[] data)
 {
     using (MemoryStream destination = new MemoryStream())
     using (MemoryStream source = new MemoryStream(data))
     {
         DeflateStream deflate = new DeflateStream(source, CompressionMode.Decompress);
         deflate.CopyTo(destination);
         return destination.GetBuffer();
     }
 }
开发者ID:PQ4NOEH,项目名称:.NET-recipes,代码行数:10,代码来源:DeflateSpec.cs

示例14: Decompress

 public byte[] Decompress(byte[] input)
 {
     using (var inputStream = new MemoryStream(input))
     using (var decompressionStream = new DeflateStream(inputStream, CompressionMode.Decompress))
     using (var outputStream = new MemoryStream())
     {
         decompressionStream.CopyTo(outputStream);
         return outputStream.ToArray();
     }
 }
开发者ID:fenix2222,项目名称:Nimbus,代码行数:10,代码来源:DeflateCompressor.cs

示例15: Decompress

 public static byte[] Decompress(byte[] compressedData)
 {
     using (MemoryStream compressedStream = new MemoryStream(compressedData))
     using (MemoryStream decompressedStream = new MemoryStream())
     using (DeflateStream decompressionStream = new DeflateStream(compressedStream, CompressionMode.Decompress))
     {
         decompressionStream.CopyTo(decompressedStream);
         return decompressedStream.GetBuffer();
     }
 }
开发者ID:dorav,项目名称:deflate_example,代码行数:10,代码来源:test.cs


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