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


C# zlib.ZStream类代码示例

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


ZStream类属于ComponentAce.Compression.Libs.zlib命名空间,在下文中一共展示了ZStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compress

 // Do we really need these? SWGEmu doesn't seem to compress...
 public void Compress()
 {
     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.deflateInit(6);
     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.deflate(4) != -3)
     {
         long totalOut = zStream.total_out;
         zStream.deflateEnd();
         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,代码行数:33,代码来源:PacketStream.cs

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

示例3: InfBlocks

        internal int write; // window write pointer 

        internal InfBlocks(ZStream z, object checkfn, int w)
        {
            hufts = new int[MANY*3];
            window = new byte[w];
            end = w;
            this.checkfn = checkfn;
            mode = TYPE;
            reset(z, null);
        }
开发者ID:jakop345,项目名称:NVNC,代码行数:11,代码来源:InfBlocks.cs

示例4: InfCodes

 internal InfCodes(int bl, int bd, int[] tl, int[] td, ZStream z)
 {
     mode = START;
     lbits = (byte) bl;
     dbits = (byte) bd;
     ltree = tl;
     ltree_index = 0;
     dtree = td;
     dtree_index = 0;
 }
开发者ID:jakop345,项目名称:NVNC,代码行数:10,代码来源:InfCodes.cs

示例5: reset

        internal void reset(ZStream z, long[] c)
        {
            if (c != null)
                c[0] = check;
            if (mode == BTREE || mode == DTREE)
            {
                blens = null;
            }
            if (mode == CODES)
            {
                codes.free(z);
            }
            mode = TYPE;
            bitk = 0;
            bitb = 0;
            read = write = 0;

            if (checkfn != null)
                z.adler = check = z._adler.adler32(0L, null, 0, 0);
        }
开发者ID:jakop345,项目名称:NVNC,代码行数:20,代码来源:InfBlocks.cs

示例6: free

 internal void  free(ZStream z)
 {
     reset(z, null);
     window = null;
     hufts = null;
     //ZFREE(z, s);
 }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:7,代码来源:InfBlocks.cs

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

示例8: deflateSetDictionary

		internal int deflateSetDictionary(ZStream strm, byte[] dictionary, int dictLength)
		{
			int length = dictLength;
			int index = 0;
			
			if (dictionary == null || status != INIT_STATE)
				return Z_STREAM_ERROR;

            strm.adler = Adler32.adler32(strm.adler, dictionary, 0, dictLength);
			
			if (length < MIN_MATCH)
				return Z_OK;
			if (length > w_size - MIN_LOOKAHEAD)
			{
				length = w_size - MIN_LOOKAHEAD;
				index = dictLength - length; // use the tail of the dictionary
			}
			Array.Copy(dictionary, index, window, 0, length);
			strstart = length;
			block_start = length;
			
			// Insert all strings in the hash table (except for the last two bytes).
			// s->lookahead stays null, so s->ins_h will be recomputed at the next
			// call of fill_window.
			
			ins_h = window[0] & 0xff;
			ins_h = (((ins_h) << hash_shift) ^ (window[1] & 0xff)) & hash_mask;
			
			for (int n = 0; n <= length - MIN_MATCH; n++)
			{
				ins_h = (((ins_h) << hash_shift) ^ (window[(n) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
				prev[n & w_mask] = head[ins_h];
				head[ins_h] = (short) n;
			}
			return Z_OK;
		}
开发者ID:radinamatic,项目名称:subtitleedit,代码行数:36,代码来源:Deflate.cs

示例9: deflateReset

		internal int deflateReset(ZStream strm)
		{
			strm.total_in = strm.total_out = 0;
			strm.msg = null; //
			strm.data_type = Z_UNKNOWN;
			
			pending = 0;
			pending_out = 0;
			
			if (noheader < 0)
			{
				noheader = 0; // was set to -1 by deflate(..., Z_FINISH);
			}
			status = (noheader != 0)?BUSY_STATE:INIT_STATE;
            strm.adler = Adler32.adler32(0, null, 0, 0);
			
			last_flush = Z_NO_FLUSH;
			
			tr_init();
			lm_init();
			return Z_OK;
		}
开发者ID:radinamatic,项目名称:subtitleedit,代码行数:22,代码来源:Deflate.cs

示例10: deflateInit

		internal int deflateInit(ZStream strm, int level, int bits)
		{
			return deflateInit2(strm, level, Z_DEFLATED, bits, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
		}
开发者ID:radinamatic,项目名称:subtitleedit,代码行数:4,代码来源:Deflate.cs

示例11: EndZlibOperation

 protected override int EndZlibOperation(ZStream zs)
 {
     return zs.inflateEnd();
 }
开发者ID:Ashod,项目名称:Phalanger,代码行数:4,代码来源:ZlibFilter.cs

示例12: inflate_fast

        // Called with number of bytes left to write in window at least 258
        // (the maximum string length) and number of input bytes available
        // at least ten.  The ten bytes are six bytes for the longest length/
        // distance pair plus four bytes for overloading the bit buffer.

        internal int inflate_fast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InfBlocks s, ZStream z)
        {
            int t; // temporary pointer
            int[] tp; // temporary pointer
            int tp_index; // temporary pointer
            int e; // extra bits or operation
            int b; // bit buffer
            int k; // bits in bit buffer
            int p; // input data pointer
            int n; // bytes available there
            int q; // output window write pointer
            int m; // bytes to end of window or read pointer
            int ml; // mask for literal/length tree
            int md; // mask for distance tree
            int c; // bytes to copy
            int d; // distance back to copy from
            int r; // copy source pointer

            // load input, output, bit values
            p = z.next_in_index; n = z.avail_in; b = s.bitb; k = s.bitk;
            q = s.write; m = q < s.read ? s.read - q - 1 : s.end - q;

            // initialize masks
            ml = inflate_mask[bl];
            md = inflate_mask[bd];

            // do until not enough input or output space for fast loop
            do
            {
                // assume called with m >= 258 && n >= 10
                // get literal/length code
                while (k < (20))
                {
                    // max bits for literal/length code
                    n--;
                    b |= (z.next_in[p++] & 0xff) << k; k += 8;
                }

                t = b & ml;
                tp = tl;
                tp_index = tl_index;
                if ((e = tp[(tp_index + t) * 3]) == 0)
                {
                    b >>= (tp[(tp_index + t) * 3 + 1]); k -= (tp[(tp_index + t) * 3 + 1]);

                    s.window[q++] = (byte)tp[(tp_index + t) * 3 + 2];
                    m--;
                    continue;
                }
                do
                {

                    b >>= (tp[(tp_index + t) * 3 + 1]); k -= (tp[(tp_index + t) * 3 + 1]);

                    if ((e & 16) != 0)
                    {
                        e &= 15;
                        c = tp[(tp_index + t) * 3 + 2] + ((int)b & inflate_mask[e]);

                        b >>= e; k -= e;

                        // decode distance base of block to copy
                        while (k < (15))
                        {
                            // max bits for distance code
                            n--;
                            b |= (z.next_in[p++] & 0xff) << k; k += 8;
                        }

                        t = b & md;
                        tp = td;
                        tp_index = td_index;
                        e = tp[(tp_index + t) * 3];

                        do
                        {

                            b >>= (tp[(tp_index + t) * 3 + 1]); k -= (tp[(tp_index + t) * 3 + 1]);

                            if ((e & 16) != 0)
                            {
                                // get extra bits to add to distance base
                                e &= 15;
                                while (k < (e))
                                {
                                    // get extra bits (up to 13)
                                    n--;
                                    b |= (z.next_in[p++] & 0xff) << k; k += 8;
                                }

                                d = tp[(tp_index + t) * 3 + 2] + (b & inflate_mask[e]);

                                b >>= (e); k -= (e);

                                // do the copy
//.........这里部分代码省略.........
开发者ID:ChrisJamesSadler,项目名称:Cosmos,代码行数:101,代码来源:zLib.cs

示例13: free

 internal void free(ZStream z)
 {
     //  ZFREE(z, c);
 }
开发者ID:ChrisJamesSadler,项目名称:Cosmos,代码行数:4,代码来源:zLib.cs

示例14: proc

        internal int proc(InfBlocks s, ZStream z, int r)
        {
            int j; // temporary storage
            //int[] t; // temporary pointer
            int tindex; // temporary pointer
            int e; // extra bits or operation
            int b = 0; // bit buffer
            int k = 0; // bits in bit buffer
            int p = 0; // input data pointer
            int n; // bytes available there
            int q; // output window write pointer
            int m; // bytes to end of window or read pointer
            int f; // pointer to copy strings from

            // copy input/output information to locals (UPDATE macro restores)
            p = z.next_in_index; n = z.avail_in; b = s.bitb; k = s.bitk;
            q = s.write; m = q < s.read ? s.read - q - 1 : s.end - q;

            // process input and output based on current state
            while (true)
            {
                switch (mode)
                {

                    // waiting for "i:"=input, "o:"=output, "x:"=nothing
                    case START:  // x: set up for LEN
                        if (m >= 258 && n >= 10)
                        {

                            s.bitb = b; s.bitk = k;
                            z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                            s.write = q;
                            r = inflate_fast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, s, z);

                            p = z.next_in_index; n = z.avail_in; b = s.bitb; k = s.bitk;
                            q = s.write; m = q < s.read ? s.read - q - 1 : s.end - q;

                            if (r != Z_OK)
                            {
                                mode = r == Z_STREAM_END ? WASH : BADCODE;
                                break;
                            }
                        }
                        need = lbits;
                        tree = ltree;
                        tree_index = ltree_index;

                        mode = LEN;
                        goto case LEN;

                    case LEN:  // i: get length/literal/eob next
                        j = need;

                        while (k < (j))
                        {
                            if (n != 0)
                                r = Z_OK;
                            else
                            {

                                s.bitb = b; s.bitk = k;
                                z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                                s.write = q;
                                return s.inflate_flush(z, r);
                            }
                            n--;
                            b |= (z.next_in[p++] & 0xff) << k;
                            k += 8;
                        }

                        tindex = (tree_index + (b & inflate_mask[j])) * 3;

                        b = SupportClass.URShift(b, (tree[tindex + 1]));
                        k -= (tree[tindex + 1]);

                        e = tree[tindex];

                        if (e == 0)
                        {
                            // literal
                            lit = tree[tindex + 2];
                            mode = LIT;
                            break;
                        }
                        if ((e & 16) != 0)
                        {
                            // length
                            get_Renamed = e & 15;
                            len = tree[tindex + 2];
                            mode = LENEXT;
                            break;
                        }
                        if ((e & 64) == 0)
                        {
                            // next table
                            need = e;
                            tree_index = tindex / 3 + tree[tindex + 2];
                            break;
                        }
                        if ((e & 32) != 0)
//.........这里部分代码省略.........
开发者ID:ChrisJamesSadler,项目名称:Cosmos,代码行数:101,代码来源:zLib.cs

示例15: inflateSyncPoint

 // Returns true if inflate is currently at the end of a block generated
 // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
 // implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
 // but removes the length bytes of the resulting empty stored block. When
 // decompressing, PPP checks that at the end of input packet, inflate is
 // waiting for these length bytes.
 internal int inflateSyncPoint(ZStream z)
 {
     if (z == null || z.istate == null || z.istate.blocks == null)
         return Z_STREAM_ERROR;
     return z.istate.blocks.sync_point();
 }
开发者ID:ChrisJamesSadler,项目名称:Cosmos,代码行数:12,代码来源:zLib.cs


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