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

C# Zlib.ZlibCodec类代码示例

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

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



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

示例1: DeflateStream

 public DeflateStream( Stream stream, bool leaveOpen )
 {
     _stream = stream;
     _leaveOpen = leaveOpen;
     workBuffer = new byte[16384]; // TODO: 1024 bytes?
     z = new ZlibCodec();
 }
开发者ID:lavajoe,项目名称:ClassicalSharp,代码行数:7,代码来源:DeflateStream.cs


示例2: Initialize

        internal int Initialize(ZlibCodec codec, int w)
        {
            _codec = codec;
            _codec.Message = null;
            blocks = null;

            // handle undocumented nowrap option (no zlib header or check)
            //nowrap = 0;
            //if (w < 0)
            //{
            //    w = - w;
            //    nowrap = 1;
            //}

            // set window size
            if (w < 8 || w > 15)
            {
                End();
                throw new ZlibException("Bad window size.");

                //return ZlibConstants.Z_STREAM_ERROR;
            }
            wbits = w;

            blocks = new InflateBlocks(codec,
                                       HandleRfc1950HeaderBytes ? this : null,
                                       1 << w);

            // reset state
            Reset();
            return ZlibConstants.Z_OK;
        }
开发者ID:nzdunic,项目名称:ravendb,代码行数:32,代码来源:InflateManager.cs


示例3: InflateTreesDynamic

        internal void InflateTreesDynamic(int nl, int nd, int[] c, ref int bl, ref int bd, 
		                                  ref int tl, ref int td, int[] hp, ZlibCodec z)
        {
            // build literal/length tree
            ResetWorkArea( 288 );
            hn = 0;
            int result = BuildTree(c, 0, nl, 257, cplens, cplext, ref tl, ref bl, hp);
            if (result != RCode.Okay || bl == 0) {
                string message = null;
                if (result == RCode.DataError) {
                    message = "oversubscribed literal/length tree";
                } else {
                    message = "incomplete literal/length tree";
                }
                throw new InvalidOperationException( "Unable to inflate dynamic tree: " + message );
            }

            // build distance tree
            ResetWorkArea( 288 );
            result = BuildTree(c, nl, nd, 0, cpdist, cpdext, ref td, ref bd, hp);

            if (result != RCode.Okay || (bd == 0 && nl > 257)) {
                string message = null;
                if (result == RCode.DataError) {
                    message = "oversubscribed distance tree";
                } else if (result == RCode.BufferError) {
                    message = "incomplete distance tree";
                } else {
                    message = "empty distance tree with lengths";
                }
                throw new InvalidOperationException( "Unable to inflate dynamic tree: " + message );
            }
        }
开发者ID:Chameleonherman,项目名称:ClassicalSharp,代码行数:33,代码来源:InfTree.cs


示例4: ZlibStream

        public ZlibStream(Stream innerStream)
        {
            _inner = innerStream;

            if (_inner.CanRead)
            {
                _in = new ZlibCodec(CompressionMode.Decompress);
                //int ret = _in.InitializeInflate();
                //if (ret != ZlibConstants.Z_OK)
                //    throw new ZlibException("Unable to initialize Inflate");
                _inBuff = new byte[_bufferSize];
                _in.AvailableBytesIn = 0;
                _in.InputBuffer = _inBuff;
                _in.NextIn = 0;
            }

            if (_inner.CanWrite)
            {
                _out = new ZlibCodec(CompressionMode.Compress);
                int ret = _out.InitializeDeflate(CompressionLevel.Default);
                if (ret != ZlibConstants.Z_OK)
                    throw new ZlibException("Unable to initialize Deflate");
                _outBuff = new byte[_bufferSize];
                _out.OutputBuffer = _outBuff;
            }
        }
开发者ID:nickwhaley,项目名称:ubiety,代码行数:26,代码来源:ZlibStream.cs


示例5: Initialize

        internal void Initialize( ZlibCodec codec, int w )
        {
            _codec = codec;
            blocks = null;

            wbits = w;
            blocks = new InflateBlocks( codec, 1 << w );
            Reset();
        }
开发者ID:Chameleonherman,项目名称:ClassicalSharp,代码行数:9,代码来源:Inflate.cs


示例6: InflateTreeBits

        internal void InflateTreeBits(int[] c, ref int bb, ref int tb, int[] hp, ZlibCodec z)
        {
            ResetWorkArea( 19 );
            hn = 0;
            int result = BuildTree(c, 0, 19, 19, null, null, ref tb, ref bb, hp);

            if (result == RCode.DataError) {
                throw new InvalidOperationException( "oversubscribed dynamic bit lengths tree" );
            } else if (result == RCode.BufferError || bb == 0) {
                throw new InvalidOperationException( "incomplete dynamic bit lengths tree" );
            }
        }
开发者ID:Chameleonherman,项目名称:ClassicalSharp,代码行数:12,代码来源:InfTree.cs


示例7: WorkItem

            public WorkItem(int size, Ionic.Zlib.CompressionLevel compressLevel, CompressionStrategy strategy)
            {
                buffer= new byte[size];
                // alloc 5 bytes overhead for every block (margin of safety= 2)
                int n = size + ((size / 32768)+1) * 5 * 2;
                compressed= new byte[n];

                status = (int)Status.None;
                compressor = new ZlibCodec();
                compressor.InitializeDeflate(compressLevel, false);
                compressor.OutputBuffer = compressed;
                compressor.InputBuffer = buffer;
            }
开发者ID:tofurama3000,项目名称:substrate-minecraft,代码行数:13,代码来源:ParallelDeflateOutputStream.cs


示例8: Decompress

 /// <summary>
 /// Decompress the specified inputData.
 /// </summary>
 /// <param name="inputData">Input data.</param>
 /// <returns>decompressed byte array</returns>
 public static byte[] Decompress(byte[] inputData)
 {
     var zlib = new ZlibCodec(Ionic.Zlib.CompressionMode.Decompress);
     zlib.InputBuffer = inputData;
     zlib.OutputBuffer = new byte[MAX_PACKET_SIZE];
     zlib.NextIn = 0;
     zlib.AvailableBytesIn = inputData.Length;
     zlib.NextOut = 0;
     zlib.AvailableBytesOut = MAX_PACKET_SIZE;
     zlib.Inflate(FlushType.Finish);
     var output = new byte[zlib.TotalBytesOut];
     Array.Copy(zlib.OutputBuffer, output, (int)zlib.TotalBytesOut);
     return output;
 }
开发者ID:Lopt,项目名称:ascendancy,代码行数:19,代码来源:CompressionHelper.cs


示例9: WorkItem

 public WorkItem(int size,
                 CompressionLevel compressLevel,
                 CompressionStrategy strategy,
                 int ix)
 {
     this.buffer= new byte[size];
     // alloc 5 bytes overhead for every block (margin of safety= 2)
     int n = size + ((size / 32768)+1) * 5 * 2;
     this.compressed = new byte[n];
     this.compressor = new ZlibCodec();
     this.compressor.InitializeDeflate(compressLevel, false);
     this.compressor.OutputBuffer = this.compressed;
     this.compressor.InputBuffer = this.buffer;
     this.index = ix;
 }
开发者ID:rhlbenjamin,项目名称:azure-media-services-samples,代码行数:15,代码来源:ParallelDeflateOutputStream.cs


示例10: ZlibCodecCompress

        private static byte[] ZlibCodecCompress(string textToCompress)
        {
            int outputSize = 2048;
            byte[] output = new Byte[outputSize];
            byte[] uncompressed = UTF8Encoding.UTF8.GetBytes(textToCompress);
            int lengthToCompress = uncompressed.Length;

            // If you want a ZLIB stream, set this to true.  If you want
            // a bare DEFLATE stream, set this to false.
            bool wantRfc1950Header = false;

            using (MemoryStream ms = new MemoryStream())
            {
                ZlibCodec compressor = new ZlibCodec();
                compressor.InitializeDeflate(CompressionLevel.BestCompression, wantRfc1950Header);

                compressor.InputBuffer = uncompressed;
                compressor.AvailableBytesIn = lengthToCompress;
                compressor.NextIn = 0;
                compressor.OutputBuffer = output;

                foreach (var f in new FlushType[] { FlushType.None, FlushType.Finish })
                {
                    int bytesToWrite = 0;
                    do
                    {
                        compressor.AvailableBytesOut = outputSize;
                        compressor.NextOut = 0;
                        compressor.Deflate(f);

                        bytesToWrite = outputSize - compressor.AvailableBytesOut;
                        if (bytesToWrite > 0)
                            ms.Write(output, 0, bytesToWrite);
                    }
                    while ((f == FlushType.None && (compressor.AvailableBytesIn != 0 || compressor.AvailableBytesOut == 0)) ||
                           (f == FlushType.Finish && bytesToWrite != 0));
                }

                compressor.EndDeflate();

                ms.Flush();
                return ms.ToArray();
            }
        }
开发者ID:rlmarsh85,项目名称:bloodlines-resurgence,代码行数:44,代码来源:Compression.cs


示例11: ZLibDecompress

        public static byte[] ZLibDecompress(byte[] compressed, bool mode, int outputSize)
        {
            byte[] output = new Byte[outputSize];

            bool expectRfc1950Header = mode;

            using (MemoryStream ms = new MemoryStream())
            {
                ZlibCodec compressor = new ZlibCodec();
                compressor.InitializeInflate(expectRfc1950Header);

                compressor.InputBuffer = compressed;
                compressor.AvailableBytesIn = compressed.Length;
                compressor.NextIn = 0;
                compressor.OutputBuffer = output;

                foreach (var f in new FlushType[] { FlushType.None, FlushType.Finish })
                {
                    int bytesToWrite = 0;
                    do
                    {
                        compressor.AvailableBytesOut = outputSize;
                        compressor.NextOut = 0;
                        compressor.Inflate(f);

                        bytesToWrite = outputSize - compressor.AvailableBytesOut;
                        if (bytesToWrite > 0)
                            ms.Write(output, 0, bytesToWrite);
                    }
                    while ((f == FlushType.None && (compressor.AvailableBytesIn != 0 || compressor.AvailableBytesOut == 0)) ||
                           (f == FlushType.Finish && bytesToWrite != 0));
                }

                compressor.EndInflate();

                return (ms.ToArray());
            }
        }
开发者ID:mansemino,项目名称:Arctium,代码行数:38,代码来源:ZLib.cs


示例12: InflateBlocks

 internal InflateBlocks(ZlibCodec z, System.Object checkfn, int w)
 {
     hufts = new int[MANY * 3];
     window = new byte[w];
     end = w;
     this.checkfn = checkfn;
     mode = TYPE;
     Reset(z, null);
 }
开发者ID:gregsohl,项目名称:Cool_dotNet_Tools_Techniques_Libraries_Presentation,代码行数:9,代码来源:Inflate.cs


示例13: Process

        internal int Process(InflateBlocks blocks, ZlibCodec z, int r)
        {
            int j; // temporary storage
            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.NextIn; n = z.AvailableBytesIn; b = blocks.bitb; k = blocks.bitk;
            q = blocks.write; m = q < blocks.read ? blocks.read - q - 1 : blocks.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)
                        {

                            blocks.bitb = b; blocks.bitk = k;
                            z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                            blocks.write = q;
                            r = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks, z);

                            p = z.NextIn; n = z.AvailableBytesIn; b = blocks.bitb; k = blocks.bitk;
                            q = blocks.write; m = q < blocks.read ? blocks.read - q - 1 : blocks.end - q;

                            if (r != ZlibConstants.Z_OK)
                            {
                                mode = (r == ZlibConstants.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 = ZlibConstants.Z_OK;
                            else
                            {

                                blocks.bitb = b; blocks.bitk = k;
                                z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                                blocks.write = q;
                                return blocks.Flush(z, r);
                            }
                            n--;
                            b |= (z.InputBuffer[p++] & 0xff) << k;
                            k += 8;
                        }

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

                        b = SharedUtils.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)
                        {
                            // end of block
//.........这里部分代码省略.........
开发者ID:gregsohl,项目名称:Cool_dotNet_Tools_Techniques_Libraries_Presentation,代码行数:101,代码来源:Inflate.cs


示例14: Init

 internal void Init(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, ZlibCodec z)
 {
     mode = START;
     lbits = (byte)bl;
     dbits = (byte)bd;
     ltree = tl;
     ltree_index = tl_index;
     dtree = td;
     dtree_index = td_index;
     tree = null;
 }
开发者ID:gregsohl,项目名称:Cool_dotNet_Tools_Techniques_Libraries_Presentation,代码行数:11,代码来源:Inflate.cs


示例15: Flush

        // copy as much as possible from the sliding window to the output area
        internal int Flush(ZlibCodec z, int r)
        {
            int n;
            int p;
            int q;

            // local copies of source and destination pointers
            p = z.NextOut;
            q = read;

            // compute number of bytes to copy as far as end of window
            n = (int)((q <= write ? write : end) - q);
            if (n > z.AvailableBytesOut)
                n = z.AvailableBytesOut;
            if (n != 0 && r == ZlibConstants.Z_BUF_ERROR)
                r = ZlibConstants.Z_OK;

            // update counters
            z.AvailableBytesOut -= n;
            z.TotalBytesOut += n;

            // update check information
            if (checkfn != null)
                z._Adler32 = check = Adler.Adler32(check, window, q, n);

            // copy as far as end of window
            Array.Copy(window, q, z.OutputBuffer, p, n);
            p += n;
            q += n;

            // see if more to copy at beginning of window
            if (q == end)
            {
                // wrap pointers
                q = 0;
                if (write == end)
                    write = 0;

                // compute bytes to copy
                n = write - q;
                if (n > z.AvailableBytesOut)
                    n = z.AvailableBytesOut;
                if (n != 0 && r == ZlibConstants.Z_BUF_ERROR)
                    r = ZlibConstants.Z_OK;

                // update counters
                z.AvailableBytesOut -= n;
                z.TotalBytesOut += n;

                // update check information
                if (checkfn != null)
                    z._Adler32 = check = Adler.Adler32(check, window, q, n);

                // copy
                Array.Copy(window, q, z.OutputBuffer, p, n);
                p += n;
                q += n;
            }

            // update pointers
            z.NextOut = p;
            read = q;

            // done
            return r;
        }
开发者ID:gregsohl,项目名称:Cool_dotNet_Tools_Techniques_Libraries_Presentation,代码行数:67,代码来源:Inflate.cs


示例16: Free

 internal void Free(ZlibCodec z)
 {
     Reset(z, null);
     window = null;
     hufts = null;
     //ZFREE(z, s);
 }
开发者ID:gregsohl,项目名称:Cool_dotNet_Tools_Techniques_Libraries_Presentation,代码行数:7,代码来源:Inflate.cs


示例17: SyncPoint

 // 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 SyncPoint(ZlibCodec z)
 {
     if (z == null || z.istate == null || z.istate.blocks == null)
         return ZlibConstants.Z_STREAM_ERROR;
     return z.istate.blocks.SyncPoint();
 }
开发者ID:gregsohl,项目名称:Cool_dotNet_Tools_Techniques_Libraries_Presentation,代码行数:12,代码来源:Inflate.cs


示例18: InflateBlocks

 internal InflateBlocks(ZlibCodec codec, System.Object checkfn, int w)
 {
     _codec = codec;
     hufts = new int[MANY * 3];
     window = new byte[w];
     end = w;
     this.checkfn = checkfn;
     mode = InflateBlockMode.TYPE;
     Reset();
 }
开发者ID:EVOuser94,项目名称:RegawMOD-Bootloader-Customizer,代码行数:10,代码来源:Inflate.cs


示例19: Initialize

		internal int Initialize(ZlibCodec codec, CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy)
		{
			_codec = codec;
			_codec.Message = null;

			// validation
			if (windowBits < 9 || windowBits > 15)
				throw new ZlibException("windowBits must be in the range 9..15.");

			if (memLevel < 1 || memLevel > MEM_LEVEL_MAX)
				throw new ZlibException(String.Format("memLevel must be in the range 1.. {0}", MEM_LEVEL_MAX));

			_codec.dstate = this;

			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];

			// for memLevel==8, this will be 16384, 16k
			lit_bufsize = 1 << (memLevel + 6);

			// Use a single array as the buffer for data pending compression,
			// the output distance codes, and the output length codes (aka tree).  
			// orig comment: This works just fine since the average
			// output size for (length,distance) codes is <= 24 bits.
			pending = new byte[lit_bufsize * 4];
			_distanceOffset = lit_bufsize;
			_lengthOffset = (1 + 2) * lit_bufsize;

			// So, for memLevel 8, the length of the pending buffer is 65536. 64k.
			// The first 16k are pending bytes.
			// The middle slice, of 32k, is used for distance codes. 
			// The final 16k are length codes.

			this.compressionLevel = level;
			this.compressionStrategy = strategy;

			Reset();
			return ZlibConstants.Z_OK;
		}
开发者ID:jtmueller,项目名称:ravendb,代码行数:49,代码来源:DeflateManager.cs


示例20: End

 internal int End(ZlibCodec z)
 {
     if (blocks != null)
         blocks.Free(z);
     blocks = null;
     //    ZFREE(z, z->state);
     return ZlibConstants.Z_OK;
 }
开发者ID:gregsohl,项目名称:Cool_dotNet_Tools_Techniques_Libraries_Presentation,代码行数:8,代码来源:Inflate.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Zlib.ZlibStream类代码示例发布时间:2022-05-26
下一篇:
C# Zlib.GZipStream类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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