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


C# DeflateStream.Read方法代码示例

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


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

示例1: DecompressDeflate

        public static byte[] DecompressDeflate(Stream input)
        {
            using (var decompressor = new DeflateStream(input, CompressionMode.Decompress))
            {
                var buffer = new byte[BufferSize];

                using (var output = new MemoryStream())
                {
                    int read;
                    while ((read = decompressor.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        output.Write(buffer, 0, read);
                    }
                    return output.ToArray();
                }
            }
        }
开发者ID:venusdharan,项目名称:Titanium-Web-Proxy,代码行数:17,代码来源:Compression.cs

示例2: Zlib_ParallelDeflateStream

        public void Zlib_ParallelDeflateStream()
        {
            var sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            TestContext.WriteLine("{0}: Zlib_ParallelDeflateStream Start", sw.Elapsed);

            int sz = 256*1024 + this.rnd.Next(120000);
            string FileToCompress = System.IO.Path.Combine(TopLevelDir, String.Format("Zlib_ParallelDeflateStream.{0}.txt", sz));

            CreateAndFillFileText( FileToCompress, sz);

            TestContext.WriteLine("{0}: Created file: {1}", sw.Elapsed, FileToCompress );

            byte[] original = File.ReadAllBytes(FileToCompress);

            int crc1 = DoCrc(FileToCompress);

            TestContext.WriteLine("{0}: Original CRC: {1:X8}", sw.Elapsed, crc1 );

            byte[] working = new byte[WORKING_BUFFER_SIZE];
            int n = -1;
            long originalLength;
            MemoryStream ms1 = new MemoryStream();
            {
                using (FileStream fs1 = File.OpenRead(FileToCompress))
                {
                    originalLength = fs1.Length;
                    using (var compressor = new Ionic.Zlib.ParallelDeflateOutputStream(ms1, true))
                    {
                        while ((n = fs1.Read(working, 0, working.Length)) != 0)
                        {
                            compressor.Write(working, 0, n);
                        }
                    }
                }
                ms1.Seek(0, SeekOrigin.Begin);
            }

            TestContext.WriteLine("{0}: Compressed {1} bytes into {2} bytes", sw.Elapsed,
                                  originalLength, ms1.Length);

            var crc = new Ionic.Crc.CRC32();
            int crc2= 0;
            byte[] decompressedBytes= null;
            using (MemoryStream ms2 = new MemoryStream())
            {
                using (var decompressor = new DeflateStream(ms1, CompressionMode.Decompress, false))
                {
                    while ((n = decompressor.Read(working, 0, working.Length)) != 0)
                    {
                        ms2.Write(working, 0, n);
                    }
                }
                TestContext.WriteLine("{0}: Decompressed", sw.Elapsed);
                TestContext.WriteLine("{0}: Decompressed length: {1}", sw.Elapsed, ms2.Length);
                ms2.Seek(0, SeekOrigin.Begin);
                crc2 = crc.GetCrc32(ms2);
                decompressedBytes = ms2.ToArray();
                TestContext.WriteLine("{0}: Decompressed CRC: {1:X8}", sw.Elapsed, crc2 );
            }


            TestContext.WriteLine("{0}: Checking...", sw.Elapsed );

            bool check = true;
            if (originalLength != decompressedBytes.Length)
            {
                TestContext.WriteLine("Different lengths.");
                check = false;
            }
            else
            {
                for (int i = 0; i < decompressedBytes.Length; i++)
                {
                    if (original[i] != decompressedBytes[i])
                    {
                        TestContext.WriteLine("byte {0} differs", i);
                        check = false;
                        break;
                    }
                }
            }

            Assert.IsTrue(check,"Data check failed");
            TestContext.WriteLine("{0}: Done...", sw.Elapsed );
        }
开发者ID:bedashii,项目名称:ReturnMedz,代码行数:86,代码来源:ZlibUnitTest1.cs

示例3: Zlib_ParallelDeflateStream2

        public void Zlib_ParallelDeflateStream2()
        {
            var sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            TestContext.WriteLine("{0}: Zlib_ParallelDeflateStream2 Start", sw.Elapsed);
            int sz = (128 * 1024) /*default buffer size*/ * rnd.Next(14, 28);
            using (Stream s = new MemoryStream())
            {
                TestContext.WriteLine("{0}: Creating zip...", sw.Elapsed);
                using (Stream compressor = new Ionic.Zlib.ParallelDeflateOutputStream(s, true))
                    compressor.Write(new byte[sz], 0, sz);

                s.Position = 0;
                TestContext.WriteLine("{0}: Trying to extract...", sw.Elapsed);
                using (Stream decompressor = new Ionic.Zlib.DeflateStream(s, Ionic.Zlib.CompressionMode.Decompress, true))
                {
                    try
                    {
                        int bread = decompressor.Read(new byte[sz], 0, sz);
                        Assert.AreEqual(sz, bread, "Size of decompressed bytes does not match size of input bytes");
                    }
                    catch (Ionic.Zlib.ZlibException)
                    {
                        Assert.Fail("ParallelDeflate failed");
                    }
                }
            }
            TestContext.WriteLine("{0}: Done...", sw.Elapsed);
        }
开发者ID:jkingben,项目名称:DotNetZip.Semverd,代码行数:29,代码来源:ZlibUnitTest1.cs

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

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