Read stream from XmlReader, base64 decode it and write result to file

后端 未结 1 693
抹茶落季
抹茶落季 2021-01-27 15:38

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

相关标签:
1条回答
  • 2021-01-27 16:08

    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:

    1. 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.

    2. 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.

    0 讨论(0)
提交回复
热议问题