Basically, I want to extract the stream from the XmlReader
and directly base64 decode it to a file.
The structure of the XML file can be seen here. To get t
In order to give a definitive answer to your question I would need to see the XML you are trying to read. However, two points:
According to the documentation for Convert.FromBase64String:
The FromBase64String method is designed to process a single string that contains all the data to be decoded. To decode base-64 character data from a stream, use the System.Security.Cryptography.FromBase64Transform class.
Thus your problem may be with decoding the content in chunks rather than with reading it in chunks.
You can use XmlReader.ReadElementContentAsBase64 or XmlReader.ReadElementContentAsBase64Async for exactly this purpose. From the docs:
This method reads the element content, decodes it using Base64 encoding, and returns the decoded binary bytes (for example, an inline Base64-encoded GIF image) into the buffer.
In fact, the example in the documentation demonstrates how to extract a base64-encoded image from an XML file and write it to a binary file in chunks.