internal int Initialize(ZlibCodec codec, CompressionLevel level, int bits, CompressionStrategy compressionStrategy) { return Initialize(codec, level, bits, MEM_LEVEL_DEFAULT, compressionStrategy); }
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; }
internal int Initialize(ZlibCodec codec, CompressionLevel level) { return Initialize(codec, level, ZlibConstants.WindowBitsMax); }
internal int inflate_trees_dynamic(int nl, int nd, int[] c, int[] bl, int[] bd, int[] tl, int[] td, int[] hp, ZlibCodec z) { int result; // build literal/length tree initWorkArea(288); hn[0] = 0; result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v); if (result != Z_OK || bl[0] == 0) { if (result == Z_DATA_ERROR) { z.Message = "oversubscribed literal/length tree"; } else if (result != Z_MEM_ERROR) { z.Message = "incomplete literal/length tree"; result = Z_DATA_ERROR; } return result; } // build distance tree initWorkArea(288); result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v); if (result != Z_OK || (bd[0] == 0 && nl > 257)) { if (result == Z_DATA_ERROR) { z.Message = "oversubscribed distance tree"; } else if (result == Z_BUF_ERROR) { z.Message = "incomplete distance tree"; result = Z_DATA_ERROR; } else if (result != Z_MEM_ERROR) { z.Message = "empty distance tree with lengths"; result = Z_DATA_ERROR; } return result; } return Z_OK; }
internal int inflate_trees_bits(int[] c, int[] bb, int[] tb, int[] hp, ZlibCodec z) { int result; initWorkArea(19); hn[0] = 0; result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v); if (result == Z_DATA_ERROR) { z.Message = "oversubscribed dynamic bit lengths tree"; } else if (result == Z_BUF_ERROR || bb[0] == 0) { z.Message = "incomplete dynamic bit lengths tree"; result = Z_DATA_ERROR; } return result; }
internal static int inflate_trees_fixed(int[] bl, int[] bd, int[][] tl, int[][] td, ZlibCodec z) { bl[0] = fixed_bl; bd[0] = fixed_bd; tl[0] = fixed_tl; td[0] = fixed_td; return Z_OK; }
private void end() { if (z == null) return; if (_wantCompress) { _z.EndDeflate(); } else { _z.EndInflate(); } _z = null; }