private ThrowOutOfRange ( string name ) : void | ||
name | string | |
return | void |
/// <summary> /// Sets input data to be deflated. Should only be called when <see cref="NeedsInput"/> /// returns true /// </summary> /// <param name="buffer">The buffer containing input data.</param> /// <param name="offset">The offset of the first byte of data.</param> /// <param name="count">The number of bytes of data to use as input.</param> public void SetInput(byte[] buffer, int offset, int count) { if (buffer is null) { DeflateThrowHelper.ThrowNull(nameof(buffer)); } if (offset < 0) { DeflateThrowHelper.ThrowOutOfRange(nameof(offset)); } if (count < 0) { DeflateThrowHelper.ThrowOutOfRange(nameof(count)); } if (this.inputOff < this.inputEnd) { DeflateThrowHelper.ThrowNotProcessed(); } int end = offset + count; // We want to throw an ArgumentOutOfRangeException early. // The check is very tricky: it also handles integer wrap around. if ((offset > end) || (end > buffer.Length)) { DeflateThrowHelper.ThrowOutOfRange(nameof(count)); } this.inputBuf = buffer; this.inputOff = offset; this.inputEnd = end; }
/// <summary> /// Set the deflate level (0-9) /// </summary> /// <param name="level">The value to set the level to.</param> public void SetLevel(int level) { if ((level < 0) || (level > 9)) { DeflateThrowHelper.ThrowOutOfRange(nameof(level)); } this.goodLength = DeflaterConstants.GOOD_LENGTH[level]; this.maxLazy = DeflaterConstants.MAX_LAZY[level]; this.niceLength = DeflaterConstants.NICE_LENGTH[level]; this.maxChain = DeflaterConstants.MAX_CHAIN[level]; if (DeflaterConstants.COMPR_FUNC[level] != this.compressionFunction) { switch (this.compressionFunction) { case DeflaterConstants.DEFLATE_STORED: if (this.strstart > this.blockStart) { this.huffman.FlushStoredBlock(this.window.Span, this.blockStart, this.strstart - this.blockStart, false); this.blockStart = this.strstart; } this.UpdateHash(); break; case DeflaterConstants.DEFLATE_FAST: if (this.strstart > this.blockStart) { this.huffman.FlushBlock(this.window.Span, this.blockStart, this.strstart - this.blockStart, false); this.blockStart = this.strstart; } break; case DeflaterConstants.DEFLATE_SLOW: if (this.prevAvailable) { this.huffman.TallyLit(this.pinnedWindowPointer[this.strstart - 1] & 0xFF); } if (this.strstart > this.blockStart) { this.huffman.FlushBlock(this.window.Span, this.blockStart, this.strstart - this.blockStart, false); this.blockStart = this.strstart; } this.prevAvailable = false; this.matchLen = DeflaterConstants.MIN_MATCH - 1; break; } this.compressionFunction = DeflaterConstants.COMPR_FUNC[level]; } }