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


C# ZStream.inflateInit方法代码示例

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


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

示例1: init

        private void init(Stream innerStream)
        {
            m_stream = innerStream;
            if (m_stream.CanRead)
            {
                m_in = new ZStream();
                int ret = m_in.inflateInit();
                if (ret != zlibConst.Z_OK)
                    throw new CompressionFailedException("Unable to initialize zlib for deflate: " + ret);
                m_inbuf = new byte[bufsize];
                m_in.avail_in = 0;
                m_in.next_in = m_inbuf;
                m_in.next_in_index = 0;
            }

            if (m_stream.CanWrite)
            {
                m_out = new ZStream();
                int ret = m_out.deflateInit(zlibConst.Z_DEFAULT_COMPRESSION);
                if (ret != zlibConst.Z_OK)
                    throw new CompressionFailedException("Unable to initialize zlib for inflate: " + ret);
                m_outbuf = new byte[bufsize];
                m_out.next_out = m_outbuf;
            }
        }
开发者ID:newyorknight,项目名称:jabber.net,代码行数:25,代码来源:ZlibStream.cs

示例2: _Decompress

        private void _Decompress(Stream InStream, Stream OutStream)
        {
            var ZStream = new ZStream();

            //if (ZStream.inflateInit(-15) != zlibConst.Z_OK)
            if (ZStream.inflateInit(15) != zlibConst.Z_OK)
            {
                throw (new InvalidProgramException("Can't initialize inflater"));
            }

            var Out = new byte[4096];
            var In = new byte[4096];

            try
            {
                bool ReadedAll = false;
                while (!ReadedAll)
                {
                    int InReaded = InStream.Read(In, 0, In.Length);
                    ZStream.next_in = In;
                    ZStream.next_in_index = 0;
                    ZStream.avail_in = InReaded;

                    ZStream.next_out = Out;
                    ZStream.next_out_index = 0;
                    ZStream.avail_out = Out.Length;

                    int Status = ZStream.inflate(zlibConst.Z_FULL_FLUSH);
                    //Console.WriteLine(BitConverter.ToString(Out));

                    /*
                    Console.WriteLine(
                        "{0}, {1}, {2}, {3}",
                        ZStream.avail_out,
                        ZStream.next_out,
                        ZStream.next_out_index,
                        ZStream.total_out
                    );
                    */
                    OutStream.Write(Out, 0, (int)ZStream.next_out_index);

                    switch (Status)
                    {
                        case zlibConst.Z_OK:
                            break;
                        case zlibConst.Z_STREAM_END:
                            ReadedAll = true;
                            break;
                        default:
                            Console.Error.WriteLine("" + ZStream.msg);
                            ReadedAll = true;
                            //throw (new InvalidDataException("" + ZStream.msg));
                            break;
                    }
                }
            }
            finally
            {
                ZStream.inflateEnd();
            }
        }
开发者ID:SsJVasto,项目名称:cspspemu,代码行数:61,代码来源:sceDeflt.cs

示例3: InitZlibOperation

 protected override int InitZlibOperation(ZStream zs)
 {
     // -MAX_WBITS stands for absense of Zlib header and trailer (needed for GZIP compression and decompression)
     return zs.inflateInit(-Zlib.MAX_WBITS);
 }
开发者ID:Ashod,项目名称:Phalanger,代码行数:5,代码来源:ZlibFilter.cs

示例4: DecompressReplay

        private byte[] DecompressReplay(byte[] replayData, int index, Warcraft3Replay replay)
        {
            uint numChunks = replay.replayHeader.NumDataBlocks;
            ushort compChunkSize = BitConverter.ToUInt16(replayData, index);
            ushort decompChunkSize = BitConverter.ToUInt16(replayData, index += 2);
            index -= 2; //rewind

            byte[] decompressedData = new byte[numChunks * decompChunkSize];
            byte[] compChunk;
            byte[] decompChunk = new byte[decompChunkSize];

            ZStream stream = new ZStream();
            stream.avail_in = 0;
            stream.next_in_index = 0;

            for (int i = 0; i < numChunks; i++)
            {
                if (stream.inflateInit() != zlibConst.Z_OK)
                    return null; //error

                compChunkSize = BitConverter.ToUInt16(replayData, index);
                decompChunkSize = BitConverter.ToUInt16(replayData, index += 2);
                index += 6; //skipping checksum

                compChunk = new byte[compChunkSize];
                for (int j = 0; j < compChunkSize; j++, index++)
                    compChunk[j] = replayData[index];

                stream.avail_in = compChunkSize;
                stream.next_in = compChunk;
                stream.next_in_index = 0;

                stream.avail_out = decompChunkSize;
                stream.next_out = decompressedData;
                stream.next_out_index = i * decompChunkSize;

                stream.inflate(zlibConst.Z_NO_FLUSH);
                stream.inflateEnd();
            }

            return decompressedData;
        }
开发者ID:johnhforrest,项目名称:war3-dotnet-parser,代码行数:42,代码来源:Warcraft3ReplayParser.cs

示例5: Decompress

 public void Decompress()
 {
     byte[] numArray = new byte[this.data.Count];
     this.data.CopyTo(0, numArray, 0, this.data.Count);
     byte[] numArray1 = new byte[800];
     ZStream zStream = new ZStream()
     {
         avail_in = 0
     };
     zStream.inflateInit();
     zStream.next_in = numArray;
     zStream.next_in_index = 2;
     zStream.avail_in = (int)numArray.Length - 4;
     zStream.next_out = numArray1;
     zStream.avail_out = 800;
     if (zStream.inflate(4) != -3)
     {
         long totalOut = zStream.total_out;
         zStream.inflateEnd();
         zStream = null;
         this.data.Clear();
         this.data.Add(numArray[0]);
         this.data.Add(numArray[1]);
         for (int i = 0; (long)i < totalOut; i++)
         {
             this.data.Add(numArray1[i]);
         }
         this.data.Add(numArray[(int)numArray.Length - 3]);
         this.data.Add(numArray[(int)numArray.Length - 2]);
         this.data.Add(numArray[(int)numArray.Length - 1]);
     }
 }
开发者ID:Mesagoppinmypants,项目名称:SWGProxy,代码行数:32,代码来源:PacketStream.cs

示例6: ReadBlockDecompressed

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Block"></param>
        /// <returns></returns>
        public byte[] ReadBlockDecompressed(uint Block)
        {
            if (Block >= NumberOfBlocks)
            {
                return new byte[0];
            }
            var In = ReadBlockCompressed(Block);

            // If block is not compressed, get the contents.
            if (!Blocks[Block].IsCompressed)
            {
                return In;
            }

            var Out = new byte[this.BlockSize];

            In = (byte[])In.Concat(new byte[] { 0x00 });

            //return new GZipStream(new MemoryStream(In), CompressionMode.Decompress).ReadAll(FromStart: false);
            var ZStream = new ZStream();

            if (ZStream.inflateInit(15) != zlibConst.Z_OK)
            {
                throw (new InvalidProgramException("Can't initialize inflater"));
            }
            try
            {
                ZStream.next_in = In;
                ZStream.next_in_index = 0;
                ZStream.avail_in = In.Length;

                ZStream.next_out = Out;
                ZStream.next_out_index = 0;
                ZStream.avail_out = Out.Length;

                int Status = ZStream.inflate(zlibConst.Z_FULL_FLUSH);
                if (Status != zlibConst.Z_STREAM_END) throw (new InvalidDataException("" + ZStream.msg));
            }
            finally
            {
                ZStream.inflateEnd();
            }

            return Out;
        }
开发者ID:e-COS,项目名称:cspspemu,代码行数:50,代码来源:Dax.cs

示例7: GzInflate

        public static PhpBytes GzInflate(PhpBytes data, long length)
        {
            uint factor=1, maxfactor=16;
	        long ilength;

            ZStream zs = new ZStream();

            zs.avail_in = data.Length;
            zs.next_in = data.ReadonlyData;
            zs.total_out = 0;

            // -15 omits the header (undocumented feature of zlib)
            int status = zs.inflateInit(-15);

            if (status != zlibConst.Z_OK)
            {
                PhpException.Throw(PhpError.Warning, zError(status));
                return null;
            }

            do
            {
                ilength = length != 0 ? length : data.Length * (1 << (int)(factor++));

                try
                {
                    byte[] newOutput = new byte[ilength];

                    if (zs.next_out != null)
                    {
                        Buffer.BlockCopy(zs.next_out, 0, newOutput, 0, zs.next_out.Length);
                    }

                    zs.next_out = newOutput;
                }
                catch (OutOfMemoryException)
                {
                    zs.inflateEnd();
                    return null;
                }

                zs.next_out_index = (int)zs.total_out;
                zs.avail_out = unchecked((int)(ilength - zs.total_out));
                status = zs.inflate(zlibConst.Z_NO_FLUSH);
            }
            while ((status == zlibConst.Z_BUF_ERROR || (status == zlibConst.Z_OK && (zs.avail_in != 0 || zs.avail_out == 0))) && length == 0 && factor < maxfactor);

            zs.inflateEnd();

            if ((length != 0 && status == zlibConst.Z_OK) || factor >= maxfactor)
            {
                status = zlibConst.Z_MEM_ERROR;
            }

            if (status == zlibConst.Z_STREAM_END || status == zlibConst.Z_OK)
            {
                byte[] result = new byte[zs.total_out];
                Buffer.BlockCopy(zs.next_out, 0, result, 0, (int)zs.total_out);
                return new PhpBytes(result);
            }
            else
            {
                PhpException.Throw(PhpError.Warning, zError(status));
                return null;
            }
        }
开发者ID:proff,项目名称:Phalanger,代码行数:66,代码来源:PhpZlib.cs

示例8: ZlibUncompress

        /// <summary>
        /// Reimplements function from zlib (uncompress) that is not present in ZLIB.NET.
        /// </summary>
        /// <param name="dest">Destination array of bytes. May be trimmed if necessary.</param>
        /// <param name="source">Source array of bytes.</param>
        /// <returns>Zlib status code.</returns>
        private static int ZlibUncompress(ref byte[] dest, byte[] source)
        {
            ZStream stream = new ZStream();
            int err;

            stream.next_in = source;
            stream.avail_in = source.Length;
            stream.next_out = dest;
            stream.avail_out = dest.Length;

            err = stream.inflateInit();
            if (err != zlibConst.Z_OK) return err;

            err = stream.inflate(zlibConst.Z_FINISH);
            if (err != zlibConst.Z_STREAM_END)
            {
                stream.inflateEnd();
                return err == zlibConst.Z_OK ? zlibConst.Z_BUF_ERROR : err;
            }

            if (stream.total_out != dest.Length)
            {
                byte[] output = new byte[stream.total_out];
                Buffer.BlockCopy(stream.next_out, 0, output, 0, (int)stream.total_out);
                dest = output;
            }

            return stream.inflateEnd();
        }
开发者ID:proff,项目名称:Phalanger,代码行数:35,代码来源:PhpZlib.cs


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