public void GetBlock(DeflateInput input, OutputBuffer output, bool isFinal) { int count = 0; if (input != null) { count = Math.Min(input.Count, (output.FreeBytes - 5) - output.BitsInBuffer); if (count > 0xfffb) { count = 0xfffb; } } if (isFinal) { output.WriteBits(3, 1); } else { output.WriteBits(3, 0); } output.FlushBits(); this.WriteLenNLen((ushort) count, output); if ((input != null) && (count > 0)) { output.WriteBytes(input.Buffer, input.StartIndex, count); input.ConsumeBytes(count); } }
public void GetBlock(DeflateInput input, OutputBuffer output, bool isFinal) { int count = 0; if (input != null) { count = Math.Min(input.Count, (output.FreeBytes - 5) - output.BitsInBuffer); if (count > 0xfffb) { count = 0xfffb; } } if (isFinal) { output.WriteBits(3, 1); } else { output.WriteBits(3, 0); } output.FlushBits(); this.WriteLenNLen((ushort)count, output); if ((input != null) && (count > 0)) { output.WriteBytes(input.Buffer, input.StartIndex, count); input.ConsumeBytes(count); } }
/// <summary> /// null input means write an empty payload with formatting info. This is needed for the final block. /// </summary> public void GetBlock(DeflateInput input, OutputBuffer output, bool isFinal) { Debug.Assert(output != null); Debug.Assert(output.FreeBytes >= PaddingSize); // determine number of bytes to write int count = 0; if (input != null) { // allow space for padding and bits not yet flushed to buffer count = Math.Min(input.Count, output.FreeBytes - PaddingSize - output.BitsInBuffer); // we don't expect the output buffer to ever be this big (currently 4K), but we'll check this // just in case that changes. if (count > MaxUncompressedBlockSize - PaddingSize) { count = MaxUncompressedBlockSize - PaddingSize; } } // write header and flush bits if (isFinal) { output.WriteBits( FastEncoderStatics.BFinalNoCompressionHeaderBitCount, FastEncoderStatics.BFinalNoCompressionHeader); } else { output.WriteBits( FastEncoderStatics.NoCompressionHeaderBitCount, FastEncoderStatics.NoCompressionHeader); } // now we're aligned output.FlushBits(); // write len, nlen WriteLenNLen((ushort)count, output); // write uncompressed bytes if (input != null && count > 0) { output.WriteBytes(input.Buffer, input.StartIndex, count); input.ConsumeBytes(count); } }
// null input means write an empty payload with formatting info. This is needed for the final block. public void GetBlock(DeflateInput input, OutputBuffer output, bool isFinal) { Debug.Assert(output != null); Debug.Assert(output.FreeBytes >= PaddingSize); // determine number of bytes to write int count = 0; if (input != null) { // allow space for padding and bits not yet flushed to buffer count = Math.Min(input.Count, output.FreeBytes - PaddingSize - output.BitsInBuffer); // we don't expect the output buffer to ever be this big (currently 4K), but we'll check this // just in case that changes. if (count > MaxUncompressedBlockSize - PaddingSize) { count = MaxUncompressedBlockSize - PaddingSize; } } // write header and flush bits if (isFinal) { output.WriteBits(FastEncoderStatics.BFinalNoCompressionHeaderBitCount, FastEncoderStatics.BFinalNoCompressionHeader); } else { output.WriteBits(FastEncoderStatics.NoCompressionHeaderBitCount, FastEncoderStatics.NoCompressionHeader); } // now we're aligned output.FlushBits(); // write len, nlen WriteLenNLen((ushort)count, output); // write uncompressed bytes if (input != null && count > 0) { output.WriteBytes(input.Buffer, input.StartIndex, count); input.ConsumeBytes(count); } }