public override int ReadContentAsBase64(byte[] buffer, int index, int count)
{
// check arguments
if (buffer == null)
{
throw new ArgumentNullException(nameof(buffer));
}
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count));
}
if (index < 0)
{
throw new ArgumentOutOfRangeException(nameof(index));
}
if (buffer.Length - index < count)
{
throw new ArgumentOutOfRangeException(nameof(count));
}
// if not the first call to ReadContentAsBase64
if (_parsingFunction == ParsingFunction.InReadContentAsBinary)
{
// and if we have a correct decoder
if (_incReadDecoder == _base64Decoder)
{
// read more binary data
return ReadContentAsBinary(buffer, index, count);
}
}
// first call of ReadContentAsBase64 -> initialize (move to first text child (for elements) and initialize incremental read state)
else
{
if (_readState != ReadState.Interactive)
{
return 0;
}
if (_parsingFunction == ParsingFunction.InReadElementContentAsBinary)
{
throw new InvalidOperationException(SR.Xml_MixingBinaryContentMethods);
}
if (!XmlReader.CanReadContentAs(_curNode.type))
{
throw CreateReadContentAsException(nameof(ReadContentAsBase64));
}
if (!InitReadContentAsBinary())
{
return 0;
}
}
// setup base64 decoder
InitBase64Decoder();
// read binary data
return ReadContentAsBinary(buffer, index, count);
}