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


C# GZipStream.Close方法代码示例

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


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

示例1: compress

        static public byte[] compress(byte[] bytes)
        {

            var output = new MemoryStream();
            var gzipStream = new GZipStream(output, CompressionMode.Compress, true);
            gzipStream.Write(bytes, 0, bytes.Length);
            gzipStream.Close();
            return output.ToArray();

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

示例2: compress

        public void compress(Stream inStream, Stream outStream)
        {

            GZipStream compressionStream = new GZipStream(outStream, CompressionMode.Compress, true);

            inStream.CopyTo(compressionStream);

            compressionStream.Close();

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

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

示例4: Zlib_DisposedException_GZipStream

        public void Zlib_DisposedException_GZipStream()
        {
            string TextToCompress =  IhaveaDream;

            MemoryStream ms1= new MemoryStream();

            Stream compressor= new GZipStream(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 GZipStream(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,代码行数:36,代码来源:ZlibUnitTest1.cs

示例5: SaveMultiplayer

        public byte[] SaveMultiplayer(Player player)
        {
            //Save world to memory
            MemoryStream bytesStream = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(bytesStream);

            //Basic world info
            SaveMultiplayer(bw);

            //Managers
            tileManager.Save(bw);
            itemManager.Save(bw);
            sectorManager.Save(bw);
            dayCycleManager.Save(bw);

            //Player avatar
            bw.Write(player.objectId);
            player.Save(bw);

            bw.Flush();

            byte[] bytes = bytesStream.ToArray();

            //Write header
            MemoryStream bytesStreamFinal = new MemoryStream();
            BinaryWriter bwFinal = new BinaryWriter(bytesStreamFinal);

            bwFinal.Write(bytes.Length);
            bwFinal.Flush();

            //Compress and write world
            GZipStream gzipStream = new GZipStream(bytesStreamFinal, CompressionMode.Compress, CompressionLevel.BestSpeed, true);
            gzipStream.Write(bytes, 0, bytes.Length);
            gzipStream.Close();

            return bytesStreamFinal.ToArray();
        }
开发者ID:carriercomm,项目名称:CubeWorld,代码行数:37,代码来源:CubeWorld.cs

示例6: Save

        public byte[] Save()
        {
			//Save world to memory
			MemoryStream bytesStream = new MemoryStream();
			BinaryWriter bw = new BinaryWriter(bytesStream);
			
            Save(bw, false);
            tileManager.Save(bw);
            itemManager.Save(bw);
            avatarManager.Save(bw);
            sectorManager.Save(bw);
            dayCycleManager.Save(bw);

            bw.Flush();
			
			byte[] bytes = bytesStream.ToArray();
			
			//Write header
            MemoryStream bytesStreamFinal = new MemoryStream();
            BinaryWriter bwFinal = new BinaryWriter(bytesStreamFinal);

            bwFinal.Write(VERSION_INFO);
			bwFinal.Write(bytes.Length);
			bwFinal.Flush();
			
			//Compress and write world
			GZipStream gzipStream = new GZipStream(bytesStreamFinal, CompressionMode.Compress, CompressionLevel.BestSpeed, true);
			gzipStream.Write(bytes, 0, bytes.Length);
			gzipStream.Close();

            return bytesStreamFinal.ToArray();
        }
开发者ID:carriercomm,项目名称:CubeWorld,代码行数:32,代码来源:CubeWorld.cs

示例7: Main

        public static int Main(string[] args)
        {
            var inputFile = args[0];
            var targetFolder = args[1];

            if (!Directory.Exists(targetFolder))
                Directory.CreateDirectory(targetFolder);

            var language = _GetLanguage(args);
            var type = _GetGramType(args);
            var fictionOnly = args.Any(x => x.ToLower() == "fiction");
            var versionDate = args.Single(x => x.All(Char.IsNumber));
            var includeDependencies = args.Any(x => x.ToLower() == "include0");

            var rawHrefs = File.ReadAllLines(inputFile).Select(_GetHref).Where(x => x != null).Select(x => x.ToLower());
            var filtered = rawHrefs
                .Where(x => x.Contains(_GetNGramTypeForFilter(type).ToLower()))
                .Where(x => _FilterByLanguage(x, language))
                .Where(x => x.Contains(versionDate)).ToArray();

            var connectionString = @"Data Source=.\mssql12;Initial Catalog=NGram;Integrated Security=True";

            var oneGramLoader = new OneGramLoader();

            foreach (var rawHref in filtered)
            {
                Console.WriteLine("Downloading href {0}", rawHref);
                var req = WebRequest.CreateHttp(rawHref);
                var res = req.GetResponse();
                using (var resStream = res.GetResponseStream())
                {
                    using (var zipStream = new GZipStream(resStream, CompressionMode.Decompress))
                    {
                        using (var sr = new StreamReader(zipStream))
                        {
                            oneGramLoader.ProcessOneGram(sr, connectionString);
                        }

                        zipStream.Close();
                    }
                    resStream.Close();
                }
            }

            Console.WriteLine("Finished - any key");
            Console.ReadLine();

            return 0;
        }
开发者ID:erick-thompson,项目名称:BookNGram,代码行数:49,代码来源:Program.cs


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