• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# zlib.ZStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


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


示例17: PerformZlibOperation

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


示例18: FilterInner

        /// <summary>
        /// Performs the generic zlib stream filter operation.
        /// </summary>
        /// <param name="input">Input chunk of bytes.</param>
        /// <param name="inputOffset">Current position within the chunk.</param>
        /// <param name="closing">Value indicating whether the stream will be closed.</param>
        /// <returns>Array of available bytes (even empty one). Null on non-critical error.</returns>
        protected byte[] FilterInner(byte[] input, ref int inputOffset, bool closing)
        {
            if (_state == ZlibState.Finished)
            {
                //if stream already ended, throw an error
                PhpException.Throw(PhpError.Warning, "using zlib stream that is already finished");
                return null;
            }

            if (_state == ZlibState.Failed)
            {
                //if stream already ended, throw an error
                PhpException.Throw(PhpError.Warning, "using zlib stream that failed");
                return null;
            }

            List<Tuple<byte[], int>> subchunks = null;
            int status = zlibConst.Z_OK;

            // initialize if necessary
            if (_state == ZlibState.NotStarted)
            {
                _stream = new ZStream();

                // init algorithm
                status = InitZlibOperation(_stream);

                // check for error
                if (status != zlibConst.Z_OK)
                {
                    _state = ZlibState.Failed;
                    PhpException.Throw(PhpError.Error, Zlib.zError(status));
                    return null;
                }

                _state = ZlibState.Data;
            }

            if (_state == ZlibState.Data)
            {
                // input chunk
                _stream.next_in = input;
                _stream.next_in_index = inputOffset;
                _stream.avail_in = input.Length - inputOffset;

                long initial_total_out = _stream.total_out;
                long initial_total_in = _stream.total_in;

                int nextBufferSize = 8;
                int bufferSizeMax = 65536;

                // do while operation does some progress
                do
                {
                    _stream.next_out = new byte[nextBufferSize];
                    _stream.next_out_index = 0;
                    _stream.avail_out = _stream.next_out.Length;

                    if (nextBufferSize < bufferSizeMax)
                    {
                        nextBufferSize *= 2;
                    }

                    long previous_total_out = _stream.total_out;

                    status = PerformZlibOperation(_stream, GetFlushFlags(closing));

                    if (_stream.total_out - previous_total_out > 0)
                    {
                        // if the list was not initialize, do so
                        if (subchunks == null)
                            subchunks = new List<Tuple<byte[], int>>();

                        // add the subchunk to the list only when it contains some data
                        subchunks.Add(new Tuple<byte[], int>(_stream.next_out, (int)(_stream.total_out - previous_total_out)));
                    }
                }
                // we continue only when progress was made and there is input available
                while ((status == zlibConst.Z_OK || status == zlibConst.Z_BUF_ERROR) && (_stream.avail_in > 0 || (_stream.avail_in == 0 && _stream.avail_out == 0)));

                // if the last op wasn't the end of stream (this happens only with Z_FINISH) or general success, return error
                if (status != zlibConst.Z_STREAM_END && status != zlibConst.Z_OK)
                {
                    _state = ZlibState.Failed;
                    PhpException.Throw(PhpError.Warning, Zlib.zError(status));
                    return null;
                }

                // end the algorithm if requested
                if (closing || status == zlibConst.Z_STREAM_END)
                {
                    _state = ZlibState.Finished;

//.........这里部分代码省略.........
开发者ID:Ashod,项目名称:Phalanger,代码行数:101,代码来源:ZlibFilter.cs


示例19: inflate_trees_bits

        internal static int inflate_trees_bits(int[] c, int[] bb, int[] tb, int[] hp, ZStream z)
        {
            int r;
            var hn = new int[1]; // hufts used in space
            var v = new int[19]; // work area for huft_build 

            r = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);

            if (r == Z_DATA_ERROR)
            {
                z.msg = "oversubscribed dynamic bit lengths tree";
            }
            else if (r == Z_BUF_ERROR || bb[0] == 0)
            {
                z.msg = "incomplete dynamic bit lengths tree";
                r = Z_DATA_ERROR;
            }
            return r;
        }
开发者ID:jakop345,项目名称:NVNC,代码行数:19,代码来源:InfTree.cs


示例20: deflateInit2

		internal int deflateInit2(ZStream strm, int level, int method, int windowBits, int memLevel, int strategy)
		{
			int noheader = 0;
			//    byte[] my_version=ZLIB_VERSION;
			
			//
			//  if (version == null || version[0] != my_version[0]
			//  || stream_size != sizeof(z_stream)) {
			//  return Z_VERSION_ERROR;
			//  }
			
			strm.msg = null;
			
			if (level == Z_DEFAULT_COMPRESSION)
				level = 6;
			
			if (windowBits < 0)
			{
				// undocumented feature: suppress zlib header
				noheader = 1;
				windowBits = - windowBits;
			}
			
			if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || windowBits < 9 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY)
			{
				return Z_STREAM_ERROR;
			}
			
			strm.dstate = (Deflate) this;
			
			this.noheader = noheader;
			w_bits = windowBits;
			w_size = 1 << w_bits;
			w_mask = w_size - 1;
			
			hash_bits = memLevel + 7;
			hash_size = 1 << hash_bits;
			hash_mask = hash_size - 1;
			hash_shift = ((hash_bits + MIN_MATCH - 1) / MIN_MATCH);
			
			window = new byte[w_size * 2];
			prev = new short[w_size];
			head = new short[hash_size];
			
			lit_bufsize = 1 << (memLevel + 6); // 16K elements by default
			
			// We overlay pending_buf and d_buf+l_buf. This works since the average
			// output size for (length,distance) codes is <= 24 bits.
			pending_buf = new byte[lit_bufsize * 4];
			pending_buf_size = lit_bufsize * 4;
			
			d_buf = lit_bufsize;
			l_buf = (1 + 2) * lit_bufsize;
			
			this.level = level;
			
			//System.out.println("level="+level);
			
			this.strategy = strategy;
			this.method = (byte) method;
			
			return deflateReset(strm);
		}
开发者ID:radinamatic,项目名称:subtitleedit,代码行数:63,代码来源:Deflate.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Navigator.KryptonPage类代码示例发布时间:2022-05-24
下一篇:
C# Compiler.Expression类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap