private void InitBase64Decoder() { if (_base64Decoder == null) { _base64Decoder = new Base64Decoder(); } else { _base64Decoder.Reset(); } _decoder = _base64Decoder; }
public override async Task <int> ReadContentAsBase64Async(byte[] buffer, int index, int count) { switch (_state) { case State.Initial: case State.EndOfFile: case State.Closed: case State.Error: return(0); case State.ClearNsAttributes: case State.PopNamespaceScope: switch (NodeType) { case XmlNodeType.Element: throw CreateReadContentAsException("ReadContentAsBase64"); case XmlNodeType.EndElement: return(0); case XmlNodeType.Attribute: if (_curNsAttr != -1 && reader.CanReadBinaryContent) { CheckBuffer(buffer, index, count); if (count == 0) { return(0); } if (_nsIncReadOffset == 0) { // called first time on this ns attribute if (_binDecoder != null && _binDecoder is Base64Decoder) { _binDecoder.Reset(); } else { _binDecoder = new Base64Decoder(); } } if (_nsIncReadOffset == _curNode.value.Length) { return(0); } _binDecoder.SetNextOutputBuffer(buffer, index, count); _nsIncReadOffset += _binDecoder.Decode(_curNode.value, _nsIncReadOffset, _curNode.value.Length - _nsIncReadOffset); return(_binDecoder.DecodedCount); } goto case XmlNodeType.Text; case XmlNodeType.Text: Debug.Assert(AttributeCount > 0); return(await reader.ReadContentAsBase64Async(buffer, index, count).ConfigureAwait(false)); default: Debug.Assert(false); return(0); } case State.Interactive: _state = State.ReadContentAsBase64; goto case State.ReadContentAsBase64; case State.ReadContentAsBase64: int read = await reader.ReadContentAsBase64Async(buffer, index, count).ConfigureAwait(false); if (read == 0) { _state = State.Interactive; ProcessNamespaces(); } return(read); case State.ReadContentAsBinHex: case State.ReadElementContentAsBase64: case State.ReadElementContentAsBinHex: throw new InvalidOperationException(ResXml.Xml_MixingBinaryContentMethods); default: Debug.Assert(false); return(0); } }