Redzen.IO.MemoryBlockStream.WriteByte C# (CSharp) Method

WriteByte() public method

Writes a byte to the stream at the current position.
public WriteByte ( byte value ) : void
value byte The byte to write.
return void
        public override void WriteByte(byte value)
        {
            if(!this._isOpen) throw new ObjectDisposedException("Stream is closed.");

            // Determine new position (post write).
            int endPos = _position + 1;
            // Check for overflow
            if(endPos < 0) throw new IOException("Stream was too long.");

            // Ensure there is capacity to write the byte into.
            EnsureCapacity(endPos);

            // Write the byte into the stream.
            int blkIdx = _position / _blockSize;
            int blkOffset = _position % _blockSize;
            _blockList[blkIdx][blkOffset] = value;

            // Update state.
            _position++;
            if(_position > _length) {
                _length = _position;
            }
        }