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


C# GZipStream.CopyTo方法代码示例

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


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

示例1: uncompress

        public void uncompress(Stream inStream, Stream outStream)
        {

            GZipStream compressionStream = new GZipStream(inStream, CompressionMode.Decompress, true);

            compressionStream.CopyTo(outStream);

        }
开发者ID:superkaka,项目名称:mycsharp,代码行数:8,代码来源:GZipCompresser.cs

示例2: World

        public World(String path)
        {
            TAG_Compound data;
            LevelDatPath = path;

            using (FileStream level = new FileStream(path, FileMode.Open))
            {
                using (GZipStream decompress = new GZipStream(level, CompressionMode.Decompress))
                {
                    MemoryStream mem = new MemoryStream();
                    decompress.CopyTo(mem);
                    mem.Seek(0, SeekOrigin.Begin);
                    data = new TAG_Compound(mem);
                }
            }

            Seed = (long)data["Data"]["RandomSeed"];
            OriginalSeed = Seed;
            Version = (int)data["Data"]["version"];
            WorldName = (String)data["Data"]["LevelName"];
            WorldDir = Path.GetDirectoryName(path);
        }
开发者ID:mblaine,项目名称:BiomePainter,代码行数:22,代码来源:World.cs

示例3: GZipStreamTest

        public void GZipStreamTest()
        {
            string testString = "Some testing string to compress/decompress using the GzipStream object!";

            // compress.
            var testStringBytes = ASCIIEncoding.ASCII.GetBytes(testString);
            var compressedStream = new MemoryStream();
            var stream = new GZipStream(compressedStream, CompressionMode.Compress);
            stream.Write(testStringBytes, 0, testStringBytes.Length);
            stream.Flush();
            byte[] compressedTestString = compressedStream.ToArray();

            // decompress.
            compressedStream = new MemoryStream(compressedTestString);
            var decompressiongStream = new GZipStream(compressedStream, CompressionMode.Decompress);
            var decompressedStream = new MemoryStream();
            decompressiongStream.CopyTo(decompressedStream);
            var decompressedTestString = new byte[decompressedStream.Length];
            decompressedStream.Read(decompressedTestString, 0, decompressedTestString.Length);

            ASCIIEncoding.ASCII.GetString(decompressedTestString);
        }
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:22,代码来源:GZipStreamTests.cs

示例4: Write

        public void Write()
        {
            TAG_Compound data;

            using (FileStream level = new FileStream(LevelDatPath, FileMode.Open))
            {
                using (GZipStream decompress = new GZipStream(level, CompressionMode.Decompress))
                {
                    MemoryStream mem = new MemoryStream();
                    decompress.CopyTo(mem);
                    mem.Seek(0, SeekOrigin.Begin);
                    data = new TAG_Compound(mem);
                }
            }

            ((TAG_Long)data["Data"]["RandomSeed"]).Payload = Seed;

            using (FileStream level = new FileStream(LevelDatPath, FileMode.Truncate))
            {
                    MemoryStream mem = new MemoryStream();
                    GZipStream compress = new GZipStream(mem, CompressionMode.Compress);
                    data.Write(compress);
                    compress.Close();
                    byte[] buffer = mem.ToArray();
                    level.Write(buffer, 0, buffer.Length);
            }
        }
开发者ID:mblaine,项目名称:BiomePainter,代码行数:27,代码来源:World.cs

示例5: Decompress

        private void Decompress(Object state)
        {
            Chunk c = (Chunk)state;

            if (c.CompressionType == 1) //GZip
            {
                GZipStream decompress = new GZipStream(new MemoryStream(c.RawData), CompressionMode.Decompress);
                MemoryStream mem = new MemoryStream();
                decompress.CopyTo(mem);
                mem.Seek(0, SeekOrigin.Begin);
                c.Root = new TAG_Compound(mem);
            }
            else if (c.CompressionType == 2) //Zlib
            {
                ZlibStream decompress = new ZlibStream(new MemoryStream(c.RawData), CompressionMode.Decompress);
                MemoryStream mem = new MemoryStream();
                decompress.CopyTo(mem);
                mem.Seek(0, SeekOrigin.Begin);
                c.Root = new TAG_Compound(mem);
            }
            else
            {
                throw new Exception("Unrecognized compression type");
            }

            if (Interlocked.Decrement(ref taskCount) == 0)
                signal.Set();
        }
开发者ID:mblaine,项目名称:BiomePainter,代码行数:28,代码来源:RegionFile.cs

示例6: HandleRpcResult

        private bool HandleRpcResult(ulong messageId, int sequence, BinaryReader messageReader, TeleSharp.TL.TLMethod request)
        {
            uint code = messageReader.ReadUInt32();
            ulong requestId = messageReader.ReadUInt64();

            if (requestId == (ulong)request.MessageId)
                request.ConfirmReceived = true;

            //throw new NotImplementedException();
            /*
			lock (runningRequests)
			{
				if (!runningRequests.ContainsKey(requestId))
				{
					logger.warning("rpc response on unknown request: {0}", requestId);
					messageReader.BaseStream.Position -= 12;
					return false;
				}

				request = runningRequests[requestId];
				runningRequests.Remove(requestId);
			}
			*/

            uint innerCode = messageReader.ReadUInt32();
            if (innerCode == 0x2144ca19)
            { // rpc_error
                int errorCode = messageReader.ReadInt32();
                string errorMessage = Serializers.String.read(messageReader);

                if (errorMessage.StartsWith("FLOOD_WAIT_"))
                {
                    var resultString = Regex.Match(errorMessage, @"\d+").Value;
                    var seconds = int.Parse(resultString);
                    Debug.WriteLine($"Should wait {seconds} sec.");
                    Thread.Sleep(1000 * seconds);
                }
                else if (errorMessage.StartsWith("PHONE_MIGRATE_"))
                {
                    var resultString = Regex.Match(errorMessage, @"\d+").Value;
                    var dcIdx = int.Parse(resultString);
                    var exception = new InvalidOperationException($"Your phone number registered to {dcIdx} dc. Please update settings. See https://github.com/sochix/TLSharp#i-get-an-error-migrate_x for details.");
                    exception.Data.Add("dcId", dcIdx);
                    throw exception;
                }
                else
                {
                    throw new InvalidOperationException(errorMessage);
                }

            }
            else if (innerCode == 0x3072cfa1)
            {
                try
                {
                    // gzip_packed
                    byte[] packedData = Serializers.Bytes.read(messageReader);
                    using (var ms = new MemoryStream())
                    {
                        using (var packedStream = new MemoryStream(packedData, false))
                        using (var zipStream = new GZipStream(packedStream, CompressionMode.Decompress))
                        {
                            zipStream.CopyTo(ms);
                            ms.Position = 0;
                        }
                        using (var compressedReader = new BinaryReader(ms))
                        {
                            request.deserializeResponse(compressedReader);
                        }
                    }
                }
                catch (ZlibException ex)
                {

                }
            }
            else
            {
                messageReader.BaseStream.Position -= 4;
                request.deserializeResponse(messageReader);
            }

            return false;
        }
开发者ID:marshallmick007,项目名称:TLSharp,代码行数:84,代码来源:MtProtoSender.cs

示例7: HandleRpcResult

        private bool HandleRpcResult(ulong messageId, int sequence, BinaryReader messageReader, TeleSharp.TL.TLMethod request)
        {
            uint code = messageReader.ReadUInt32();
            ulong requestId = messageReader.ReadUInt64();

            if (requestId == (ulong)request.MessageId)
                request.ConfirmReceived = true;

            //throw new NotImplementedException();
            /*
			lock (runningRequests)
			{
				if (!runningRequests.ContainsKey(requestId))
				{
					logger.warning("rpc response on unknown request: {0}", requestId);
					messageReader.BaseStream.Position -= 12;
					return false;
				}

				request = runningRequests[requestId];
				runningRequests.Remove(requestId);
			}
			*/

            uint innerCode = messageReader.ReadUInt32();
            if (innerCode == 0x2144ca19)
            { // rpc_error
                int errorCode = messageReader.ReadInt32();
                string errorMessage = Serializers.String.read(messageReader);

                if (errorMessage.StartsWith("FLOOD_WAIT_"))
                {
                    var resultString = Regex.Match(errorMessage, @"\d+").Value;
                    var seconds = int.Parse(resultString);
                    throw new FloodException(TimeSpan.FromSeconds(seconds));
                }
                else if (errorMessage.StartsWith("PHONE_MIGRATE_"))
                {
                    var resultString = Regex.Match(errorMessage, @"\d+").Value;
                    var dcIdx = int.Parse(resultString);
                    throw new PhoneMigrationException(dcIdx);
                }
                else if (errorMessage.StartsWith("FILE_MIGRATE_"))
                {
                    var resultString = Regex.Match(errorMessage, @"\d+").Value;
                    var dcIdx = int.Parse(resultString);
                    throw new FileMigrationException(dcIdx);
                }
                else if (errorMessage.StartsWith("USER_MIGRATE_"))
                {
                    var resultString = Regex.Match(errorMessage, @"\d+").Value;
                    var dcIdx = int.Parse(resultString);
                    throw new UserMigrationException(dcIdx);
                }
                else if (errorMessage == "PHONE_CODE_INVALID")
                {
                    throw new InvalidPhoneCodeException("The numeric code used to authenticate does not match the numeric code sent by SMS/Telegram");
                }
                else if (errorMessage == "SESSION_PASSWORD_NEEDED")
                {
                    throw new CloudPasswordNeededException("This Account has Cloud Password !");
                }
                else
                {
                    throw new InvalidOperationException(errorMessage);
                }

            }
            else if (innerCode == 0x3072cfa1)
            {
                try
                {
                    // gzip_packed
                    byte[] packedData = Serializers.Bytes.read(messageReader);
                    using (var ms = new MemoryStream())
                    {
                        using (var packedStream = new MemoryStream(packedData, false))
                        using (var zipStream = new GZipStream(packedStream, CompressionMode.Decompress))
                        {
                            zipStream.CopyTo(ms);
                            ms.Position = 0;
                        }
                        using (var compressedReader = new BinaryReader(ms))
                        {
                            request.deserializeResponse(compressedReader);
                        }
                    }
                }
                catch (ZlibException ex)
                {

                }
            }
            else
            {
                messageReader.BaseStream.Position -= 4;
                request.deserializeResponse(messageReader);
            }

            return false;
//.........这里部分代码省略.........
开发者ID:sochix,项目名称:TLSharp,代码行数:101,代码来源:MtProtoSender.cs

示例8: Read

        //http://www.minecraftwiki.net/wiki/Region_file_format
        public void Read(String path)
        {
            Chunks = new Chunk[32, 32];
            Match m = Regex.Match(path, @"r\.(-?\d+)\.(-?\d+)\.mc[ar]");
            Coords.X = int.Parse(m.Groups[1].Value);
            Coords.Z = int.Parse(m.Groups[2].Value);

            byte[] header = new byte[8192];

            using (BinaryReader file = new BinaryReader(File.Open(path, FileMode.Open)))
            {
                file.Read(header, 0, 8192);

                for (int chunkZ = 0; chunkZ < 32; chunkZ++)
                {
                    for (int chunkX = 0; chunkX < 32; chunkX++)
                    {
                        Chunk c = new Chunk();
                        c.Coords.X = Coords.X;
                        c.Coords.Z = Coords.Z;
                        c.Coords.RegiontoChunk();
                        c.Coords.Add(chunkX, chunkZ);

                        int i = 4 * (chunkX + chunkZ * 32);

                        byte[] temp = new byte[4];
                        temp[0] = 0;
                        Array.Copy(header, i, temp, 1, 3);
                        if (BitConverter.IsLittleEndian)
                            Array.Reverse(temp);
                        long offset = ((long)BitConverter.ToInt32(temp, 0)) * 4096;
                        int length = header[i + 3] * 4096;

                        temp = new byte[4];
                        Array.Copy(header, i + 4096, temp, 0, 4);
                        if (BitConverter.IsLittleEndian)
                            Array.Reverse(temp);
                        c.Timestamp = BitConverter.ToInt32(temp, 0);

                        if (offset == 0 && length == 0)
                        {
                            Chunks[chunkX, chunkZ] = c;
                            continue;
                        }

                        file.BaseStream.Seek(offset, SeekOrigin.Begin);

                        temp = new byte[4];
                        file.Read(temp, 0, 4);
                        if (BitConverter.IsLittleEndian)
                            Array.Reverse(temp);
                        int exactLength = BitConverter.ToInt32(temp, 0);

                        c.CompressionType = file.ReadByte();
                        if (c.CompressionType == 1) //GZip
                        {
                            c.RawData = new byte[exactLength - 1];
                            file.Read(c.RawData, 0, exactLength - 1);

                            GZipStream decompress = new GZipStream(new MemoryStream(c.RawData), CompressionMode.Decompress);
                            MemoryStream mem = new MemoryStream();
                            decompress.CopyTo(mem);
                            mem.Seek(0, SeekOrigin.Begin);
                            c.Root = new TAG_Compound(mem);
                        }
                        else if (c.CompressionType == 2) //Zlib
                        {
                            c.RawData = new byte[exactLength - 1];
                            file.Read(c.RawData, 0, exactLength - 1);

                            ZlibStream decompress = new ZlibStream(new MemoryStream(c.RawData), CompressionMode.Decompress);
                            MemoryStream mem = new MemoryStream();
                            decompress.CopyTo(mem);
                            mem.Seek(0, SeekOrigin.Begin);
                            c.Root = new TAG_Compound(mem);
                        }
                        else
                        {
                            throw new Exception("Unrecognized compression type");
                        }

                        Chunks[chunkX, chunkZ] = c;
                    }
                }

                file.Close();
            }
        }
开发者ID:mblaine,项目名称:NbtViewer,代码行数:89,代码来源:RegionFile.cs

示例9: Decompress

 private byte[] Decompress(byte[] bytes)
 {
     if (bytes[0] == 0x1f && bytes[1] == 0x8b)
     {
         using (MemoryStream memory = new MemoryStream(bytes))
         {
             using (GZipStream gzip = new GZipStream(memory, CompressionMode.Decompress))
             {
                 using (MemoryStream result = new MemoryStream())
                 {
                     gzip.CopyTo(result);
                     return result.ToArray();
                 }
             }
         }
     }
     if (bytes[0] == 0x78 && bytes[1] == 0x9c)
     {
         using (MemoryStream memory = new MemoryStream(bytes))
         {
             using (ZlibStream deflate = new ZlibStream(memory, CompressionMode.Decompress))
             {
                 using (MemoryStream result = new MemoryStream())
                 {
                     deflate.CopyTo(result);
                     return result.ToArray();
                 }
             }
         }
     }
     return bytes;
 }
开发者ID:jbrwn,项目名称:tc,代码行数:32,代码来源:MapnikVectorTileProvider.cs


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