/// <summary> /// Initializes a new instance of the <see cref="Inflate"/> class. /// </summary> /// <param name="zStream">The zlib stream.</param> /// <param name="windowBits">The window size in bits.</param> public Inflate(ZLibStream zStream, int windowBits) { this.zStream = zStream; // Handle undocumented nowrap option (no zlib header or check) if (windowBits < 0) { windowBits = -windowBits; this.NoWrap = true; } // Set window size if (windowBits < 8 || windowBits > 15) { ThrowHelper.ThrowArgumentRangeException(nameof(windowBits)); } this.WindowBits = windowBits; this.Blocks = new InflateBlocks(zStream, !this.NoWrap, 1 << windowBits); // Reset state InflateReset(zStream, this); }
public Deflate( ZLibStream zStream, ZlibOptions options, int method, int windowBits, int memLevel) { int noheader = 0; zStream.Message = null; CompressionLevel level = options.CompressionLevel.GetValueOrDefault(); CompressionStrategy strategy = options.CompressionStrategy; if (level == CompressionLevel.DefaultCompression) { level = CompressionLevel.Level6; } if (level == CompressionLevel.NoCompression) { memLevel = DEFNOCOMPRESSIONMEMLEVEL; } if (windowBits < 0) { // undocumented feature: suppress zlib header noheader = 1; windowBits = -windowBits; } if (memLevel < 1 || memLevel > MAXMEMLEVEL) { ThrowHelper.ThrowArgumentRangeException(nameof(memLevel)); } if (method != ZDEFLATED) { ThrowHelper.ThrowArgumentRangeException(nameof(method)); } if (windowBits < 9 || windowBits > 15) { ThrowHelper.ThrowArgumentRangeException(nameof(windowBits)); } if (level < CompressionLevel.NoCompression || level > CompressionLevel.BestCompression) { ThrowHelper.ThrowArgumentRangeException(nameof(level)); } if (strategy < CompressionStrategy.DefaultStrategy || strategy > CompressionStrategy.Fixed) { ThrowHelper.ThrowArgumentRangeException(nameof(strategy)); } #if USE_QUICK if (level == ZlibCompressionLevel.ZBESTSPEED) { windowBits = 13; } #endif this.NoHeader = noheader; this.wBits = windowBits; this.wSize = 1 << this.wBits; this.wMask = this.wSize - 1; this.hashBits = memLevel + 7; this.hashSize = 1 << this.hashBits; this.hashMask = (uint)this.hashSize - 1; this.litBufsize = 1 << (memLevel + 6); // 16K elements by default this.dBuf = this.litBufsize; this.lBuf = (1 + 2) * this.litBufsize; this.level = level; this.Strategy = strategy; this.method = (byte)method; this.FixedBuffers = new FixedLengthBuffers(); this.DynamicBuffers = new DynamicLengthBuffers(this.wSize, this.hashSize, this.litBufsize * 4); this.DeflateReset(zStream); }