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


C# ZlibStream.Close方法代码示例

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


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

示例1: Decompress

        /// <summary>
        /// Decompress a byte array into another byte array of the specified size
        /// </summary>
        /// <param name="to_decompress">Data to decompress</param>
        /// <param name="size_uncompressed">Size of the data once decompressed</param>
        /// <returns>Decompressed data as a byte array</returns>

        public static byte[] Decompress(byte[] to_decompress, int size_uncompressed)
        {
            ZlibStream stream = new ZlibStream(new System.IO.MemoryStream(to_decompress, false), CompressionMode.Decompress);
            byte[] packetData_decompressed = new byte[size_uncompressed];
            stream.Read(packetData_decompressed, 0, size_uncompressed);
            stream.Close();
            return packetData_decompressed;
        }
开发者ID:corwinbass,项目名称:Minecraft-Console-Client,代码行数:15,代码来源:ZlibUtils.cs

示例2: compress

        public void compress(Stream inStream, Stream outStream)
        {

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

            inStream.CopyTo(compressionStream);

            compressionStream.Close();

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

示例3: CompressBuffer

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

示例4: Compress

        /// <summary>
        /// Compress a byte array into another bytes array using Zlib compression
        /// </summary>
        /// <param name="to_compress">Data to compress</param>
        /// <returns>Compressed data as a byte array</returns>

        public static byte[] Compress(byte[] to_compress)
        {
            ZlibStream stream = new ZlibStream(new System.IO.MemoryStream(to_compress, false), CompressionMode.Compress);
            List<byte> temp_compression_list = new List<byte>();
            byte[] b = new byte[1];
            while (true)
            {
                int read = stream.Read(b, 0, 1);
                if (read > 0) { temp_compression_list.Add(b[0]); }
                else break;
            }
            stream.Close();
            return temp_compression_list.ToArray();
        }
开发者ID:corwinbass,项目名称:Minecraft-Console-Client,代码行数:20,代码来源:ZlibUtils.cs

示例5: ZDecompressBytesToOsd

        public static OSD ZDecompressBytesToOsd(byte[] input)
        {
            OSD osd = null;

            using (MemoryStream msSinkUnCompressed = new MemoryStream())
            {
                using (Ionic.Zlib.ZlibStream zOut = new Ionic.Zlib.ZlibStream(msSinkUnCompressed, CompressionMode.Decompress, true))
                {
                    CopyStream(new MemoryStream(input), zOut);
                    zOut.Close();
                }
                msSinkUnCompressed.Seek(0L, SeekOrigin.Begin);
                osd = OSDParser.DeserializeLLSDBinary(msSinkUnCompressed.ToArray());
            }

            return osd;
        }
开发者ID:hippie-b,项目名称:opensim,代码行数:17,代码来源:MaterialsDemoModule.cs

示例6: ZCompressOSD

        public static OSD ZCompressOSD(OSD inOsd, bool useHeader)
        {
            OSD osd = null;

            using (MemoryStream msSinkCompressed = new MemoryStream())
            {
                using (Ionic.Zlib.ZlibStream zOut = new Ionic.Zlib.ZlibStream(msSinkCompressed, 
                    Ionic.Zlib.CompressionMode.Compress, CompressionLevel.BestCompression, true))
                {
                    CopyStream(new MemoryStream(OSDParser.SerializeLLSDBinary(inOsd, useHeader)), zOut);
                    zOut.Close();
                }

                msSinkCompressed.Seek(0L, SeekOrigin.Begin);
                osd = OSD.FromBinary( msSinkCompressed.ToArray());
            }

            return osd;
        }
开发者ID:hippie-b,项目名称:opensim,代码行数:19,代码来源:MaterialsDemoModule.cs

示例7: Write

        public void Write(String path, bool force = false)
        {
            if (!force && !Dirty)
                return;
            byte[] header = new byte[8192];
            Array.Clear(header, 0, 8192);

            Int32 sectorOffset = 2;
            using (BinaryWriter file = new BinaryWriter(File.Exists(path) ? File.Open(path, FileMode.Truncate) : File.Open(path, FileMode.Create)))
            {
                file.Write(header, 0, 8192);

                for (int chunkX = 0; chunkX < 32; chunkX++)
                {
                    for (int chunkZ = 0; chunkZ < 32; chunkZ++)
                    {
                        Chunk c = Chunks[chunkX, chunkZ];
                        if (c == null)
                            continue;

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

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

                        if (c.Root == null)
                        {
                            Array.Clear(temp, 0, 4);
                            Array.Copy(temp, 0, header, i, 4);
                            continue;
                        }

                        temp = BitConverter.GetBytes(sectorOffset);
                        if (BitConverter.IsLittleEndian)
                            Array.Reverse(temp);
                        Array.Copy(temp, 1, header, i, 3);

                        if (c.RawData == null || force || c.Dirty)
                        {
                            //this is the performance bottleneck when doing 1024 chunks in a row;
                            //trying to only do when necessary
                            MemoryStream mem = new MemoryStream();
                            ZlibStream zlib = new ZlibStream(mem, CompressionMode.Compress);
                            c.Root.Write(zlib);
                            zlib.Close();
                            c.RawData = mem.ToArray();
                            c.CompressionType = 2;
                        }

                        temp = BitConverter.GetBytes(c.RawData.Length + 1);
                        if (BitConverter.IsLittleEndian)
                            Array.Reverse(temp);

                        file.Write(temp, 0, 4);
                        file.Write(c.CompressionType);
                        file.Write(c.RawData, 0, c.RawData.Length);

                        byte[] padding = new byte[(4096 - ((c.RawData.Length + 5) % 4096))];
                        Array.Clear(padding, 0, padding.Length);
                        file.Write(padding);

                        header[i + 3] = (byte)((c.RawData.Length + 5) / 4096 + 1);
                        sectorOffset += (c.RawData.Length + 5) / 4096 + 1;
                        c.Dirty = false;
                    }
                }

                file.Seek(0, SeekOrigin.Begin);
                file.Write(header, 0, 8192);
                file.Flush();
                file.Close();
                Dirty = false;
            }
        }
开发者ID:mblaine,项目名称:BiomePainter,代码行数:76,代码来源:RegionFile.cs

示例8: InflatePictureData

        /// <summary>
        /// Decompresses the provided data, returning the inflated result.
        /// </summary>
        /// <param name="data">the deflated picture data.</param>
        /// <returns>the inflated picture data.</returns>
        private static byte[] InflatePictureData(byte[] data)
        {
            MemoryStream out1 = new MemoryStream();
            ZlibStream in1 = null;
            try
            {
                in1 = new ZlibStream(
                    new MemoryStream(data), CompressionMode.Decompress);

                byte[] buf = new byte[4096];
                int ReadBytes;
                while ((ReadBytes = in1.Read(buf, 0, buf.Length)) > 0)
                {
                    out1.Write(buf, 0, ReadBytes);
                }
                return out1.ToArray();
            }
            catch (IOException e)
            {
                log.Log(POILogger.INFO, "Possibly corrupt compression or non-compressed data", e);
                return data;
            }
            finally
            {
                out1.Close();
                if (in1 != null)
                {
                    in1.Close();
                }
            }
        }
开发者ID:babywzazy,项目名称:Server,代码行数:36,代码来源:EscherPictBlip.cs

示例9: Zlib_ZlibStream_CompressWhileWriting

        public void Zlib_ZlibStream_CompressWhileWriting()
        {
            System.IO.MemoryStream msSinkCompressed;
            System.IO.MemoryStream msSinkDecompressed;
            ZlibStream zOut;

            // first, compress:
            msSinkCompressed = new System.IO.MemoryStream();
            zOut = new ZlibStream(msSinkCompressed, CompressionMode.Compress, CompressionLevel.BestCompression, true);
            CopyStream(StringToMemoryStream(IhaveaDream), zOut);
            zOut.Close();

            // at this point, msSinkCompressed contains the compressed bytes

            // now, decompress:
            msSinkDecompressed = new System.IO.MemoryStream();
            zOut = new ZlibStream(msSinkDecompressed, CompressionMode.Decompress);
            msSinkCompressed.Position = 0;
            CopyStream(msSinkCompressed, zOut);

            string result = MemoryStreamToString(msSinkDecompressed);
            TestContext.WriteLine("decompressed: {0}", result);
            Assert.AreEqual<String>(IhaveaDream, result);
        }
开发者ID:bedashii,项目名称:ReturnMedz,代码行数:24,代码来源:ZlibUnitTest1.cs

示例10: Zlib_DisposedException_ZlibStream

        public void Zlib_DisposedException_ZlibStream()
        {
            string TextToCompress =  IhaveaDream;

            MemoryStream ms1= new MemoryStream();

            Stream compressor= new ZlibStream(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 ZlibStream(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

示例11: DumpOld


//.........这里部分代码省略.........
                        }
                        else
                        {
                            Console.Write(", fComplex)  ");
                            Console.Write(HexDump.ToHex(n32));
                            Console.Write(" - Complex prop len");
                            Console.WriteLine(" {" + PropertyName((short)propertyId) + "}");

                            nComplex += n32;
                        }

                    }
                    // complex property data
                    while ((nComplex & remainingBytes) > 0)
                    {
                        nDumpSize = (nComplex > (int)remainingBytes) ? (short)remainingBytes : (short)nComplex;
                        HexDump.Dump(in1, 0, nDumpSize);
                        nComplex -= nDumpSize;
                        recordBytesRemaining -= nDumpSize;
                        remainingBytes -= nDumpSize;
                    }
                }
                else if (recordId == (unchecked((short)0xF012)))
                {
                    Console.Write("    Connector rule: ");
                    Console.Write(LittleEndian.ReadInt(in1));
                    Console.Write("    ShapeID A: ");
                    Console.Write(LittleEndian.ReadInt(in1));
                    Console.Write("   ShapeID B: ");
                    Console.Write(LittleEndian.ReadInt(in1));
                    Console.Write("    ShapeID connector: ");
                    Console.Write(LittleEndian.ReadInt(in1));
                    Console.Write("   Connect pt A: ");
                    Console.Write(LittleEndian.ReadInt(in1));
                    Console.Write("   Connect pt B: ");
                    Console.WriteLine(LittleEndian.ReadInt(in1));

                    recordBytesRemaining -= 24;
                    remainingBytes -= 24;
                }
                else if (recordId >= unchecked((short)0xF018) && recordId < unchecked((short)0xF117))
                {
                    Console.WriteLine("    Secondary UID: ");
                    HexDump.Dump(in1, 0, 16);
                    Console.WriteLine("    Cache of size: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Boundary top: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Boundary left: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Boundary width: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Boundary height: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    X: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Y: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Cache of saved size: " + HexDump.ToHex(LittleEndian.ReadInt(in1)));
                    Console.WriteLine("    Compression Flag: " + HexDump.ToHex((byte)in1.ReadByte()));
                    Console.WriteLine("    Filter: " + HexDump.ToHex((byte)in1.ReadByte()));
                    Console.WriteLine("    Data (after decompression): ");

                    recordBytesRemaining -= 34 + 16;
                    remainingBytes -= 34 + 16;

                    nDumpSize = (recordBytesRemaining > (int)remainingBytes) ? (short)remainingBytes : (short)recordBytesRemaining;


                    byte[] buf = new byte[nDumpSize];
                    int Read = in1.Read(buf,0,buf.Length);
                    while (Read != -1 && Read < nDumpSize)
                        Read += in1.Read(buf, Read, buf.Length);

                    MemoryStream bin = new MemoryStream(buf);
                    
                    ZlibStream in2 = new ZlibStream(bin, CompressionMode.Decompress, false);
                    int bytesToDump = -1;
                    HexDump.Dump(in2, 0, bytesToDump);

                    recordBytesRemaining -= nDumpSize;
                    remainingBytes -= nDumpSize;
                    in2.Close();
                }

                bool isContainer = (options & (short)0x000F) == (short)0x000F;
                if (isContainer && remainingBytes >= 0)
                {	// Container
                    if (recordBytesRemaining <= (int)remainingBytes)
                        Console.WriteLine("            completed within");
                    else
                        Console.WriteLine("            continued elsewhere");
                }
                else if (remainingBytes >= 0)     // -> 0x0000 ... 0x0FFF
                {
                    nDumpSize = (recordBytesRemaining > (int)remainingBytes) ? (short)remainingBytes : (short)recordBytesRemaining;

                    if (nDumpSize != 0)
                    {
                        HexDump.Dump(in1, 0, nDumpSize);
                        remainingBytes -= nDumpSize;
                    }
                }
                else
                    Console.WriteLine(" >> OVERRUN <<");
            }
        }
开发者ID:uwitec,项目名称:web-mvc-logistics,代码行数:101,代码来源:EscherDump.cs

示例12: DoCompressTests

        void DoCompressTests()
        {
            byte[] data1 = new byte[512];
            byte[] data2 = new byte[512];
            MemoryStream mstrm1;
            MemoryStream mstrm2;
            byte[] out1;
            byte[] out2;
            Random rnd = new Random();
            int csize1, csize2, osize;

            for (int i = 0; i < 512; i++)
            {
                data1[i] = (byte)(i >> 4);
                data2[i] = (byte)rnd.Next();
            }

            mstrm1 = new MemoryStream(data1, false);
            mstrm2 = new MemoryStream(data2, false);

            Console.Write("Compressing 512 non-random bytes down...");
            out1 = new byte[1024];
            MemoryStream mo1 = new MemoryStream(out1, 0, 1024, true);
            ZlibStream zstrm = new ZlibStream(mo1, CompressionMode.Compress, true);
            mstrm1.CopyTo(zstrm);
            zstrm.Close();
            csize1 = (int)mo1.Position;
            Console.WriteLine("{0} bytes", mo1.Position);

            Console.Write("Compressing 512 random bytes down...");
            out2 = new byte[1024];
            MemoryStream mo2 = new MemoryStream(out2, 0, 1024, true);
            zstrm = new ZlibStream(mo2, CompressionMode.Compress, true);
            mstrm2.CopyTo(zstrm);
            zstrm.Close();
            csize2 = (int)mo2.Position;
            Console.WriteLine("{0} bytes", mo2.Position);

            // decompress again, using ZLibDataTransformer
            byte[] final1 = new byte[1024];
            byte[] final2 = new byte[1024];

            ZLibDecompressor trns = new ZLibDecompressor();
            osize = 512;
            trns.TransformData(out1, final1, csize1, ref osize);
            Console.WriteLine("Decompressed buffer 1 back to {0} bytes", osize);
            osize = 512;
            trns.TransformData(out2, final2, csize2, ref osize);
            Console.WriteLine("Decompressed buffer 2 back to {0} bytes", osize);

            for (int i = 0; i < 512; i++)
            {
                if (final1[i] != data1[i])
                {
                    Console.WriteLine("Decompression failed for buffer 1, byte {0}", i);
                    break;
                }
                if (final2[i] != data2[i])
                {
                    Console.WriteLine("Decompression failed for buffer 2, byte {0}", i);
                    break;
                }
            }
            Console.WriteLine("Buffer comparison finished");
        }
开发者ID:darkstar,项目名称:gus,代码行数:65,代码来源:UnitTests.cs

示例13: Decompress

 /// <summary>
 /// Decompresses the specified data.
 /// </summary>
 /// <param name="data">The compressed byte array.</param>
 /// <param name="pos">The starting position into the byte array.</param>
 /// <param name="Length">The number of compressed bytes to decompress.</param>
 /// <returns>An uncompressed byte array</returns>
 public static byte[] Decompress(byte[] data, int pos, int Length)
 {
     byte[] compressedData = new byte[Length];
     Array.Copy(data, pos + 50, compressedData, 0, Length);
     ZlibStream inflaterInputStream = new ZlibStream(new MemoryStream(compressedData),CompressionMode.Decompress);
     MemoryStream out1 = new MemoryStream();
     int c;
     try
     {
         while ((c = inflaterInputStream.ReadByte()) != -1)
             out1.WriteByte((byte)c);
         return out1.ToArray();
     }
     catch (IOException e)
     {
         throw new RecordFormatException(e.ToString());
     }
     finally
     {
         out1.Close();
         if (inflaterInputStream != null)
         {
             inflaterInputStream.Close();
         }
     }
 }
开发者ID:babywzazy,项目名称:Server,代码行数:33,代码来源:EscherBlipWMFRecord.cs

示例14: Compress

 /// <summary>
 /// Compress the contents of the provided array
 /// </summary>
 /// <param name="data">An uncompressed byte array</param>
 /// <returns></returns>
 public static byte[] Compress(byte[] data)
 {
     MemoryStream out1 = new MemoryStream();
     ZlibStream deflaterOutputStream = new ZlibStream(out1, CompressionMode.Compress);
     try
     {
         //for (int i = 0; i < data.Length; i++)
         //deflaterOutputStream.WriteByte(data[i]);
         deflaterOutputStream.Write(data, 0, data.Length);   //Tony Qu changed the code
         return out1.ToArray();
     }
     catch (IOException e)
     {
         throw new RecordFormatException(e.ToString());
     }
     finally
     {
         out1.Close();
         if (deflaterOutputStream != null)
         {
             deflaterOutputStream.Close();
         }
     }
 }
开发者ID:babywzazy,项目名称:Server,代码行数:29,代码来源:EscherBlipWMFRecord.cs

示例15: InternalExtract

        private byte[] InternalExtract()
        {
            _stream.Position = _manifest.Offset;

            var sizeBytes = new byte[4];
            _stream.Read(sizeBytes, 0, 4);

            int uncompressedSize = BitConverter.ToInt32(sizeBytes, 0);
            if (uncompressedSize <= 0)
            {
                return new byte[0];
            }

            _stream.Position += 4;

            var buffer = new byte[_manifest.UncompressedSize];

            var zlibStream = new ZlibStream(_stream, CompressionMode.Decompress, true);

            zlibStream.Read(buffer, 0, buffer.Length);

            zlibStream.Close();
            zlibStream.Dispose();

            return buffer;
        }
开发者ID:andreberg,项目名称:TLII.IO,代码行数:26,代码来源:PakEntry.cs


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