Gammtek.Conduit.IO.BitStream.InternalFlushBuffer C# (CSharp) Method

InternalFlushBuffer() protected method

Flushes the internal buffer to disk.
protected InternalFlushBuffer ( bool flushAllBits ) : void
flushAllBits bool
return void
		protected void InternalFlushBuffer(bool flushAllBits)
		{
			if (flushAllBits)
			{
				// Add bits until we can write out all bits during the flush.
				var bitsToFlush = (8 - (BitBuffer.LengthBits % 8)) % 8;

				for (var i = 0; i < bitsToFlush; ++i)
				{
					BitBuffer.Write(false);
				}
			}

			var toTransfer = Math.Min(TemporaryBuffer.Length, BitBuffer.LengthBytes);

			BitBuffer.ReadBytes(TemporaryBuffer, 0, toTransfer);
			BaseStream.Write(TemporaryBuffer, 0, toTransfer);
		}
	}