By default, Base64Decode and Base64Encode are functions used to decode and encode datatypes, or best saying... STRING.
Since you want to encode a stream the Decoder must understand that it should continue from the last chunk position instead of assuming a new string, otherwise you'll get a corrupted result.
Here's how XML Writer outputs an encoded binary.
/// <method>WriteBase64</method> encodes the specified binary bytes as base64 and writes out the resulting text.
/// This method is used to write element content.<br>/// Argument:<br>/// - <var>binary</var> The binary data to output. Type of %Binary or %BinaryStream.Method WriteBase64(binary) As %Status{ If '..InRootElement Quit $$$ERROR($$$XMLNotInRootElement)
If ..OutputDestination'="device" { Set io=$io Use ..OutputFilename:(/NOXY) }
If ..InTag Write ">" Set ..InTag=0
If $isObject(binary) { Do binary.Rewind() Set len=12000 While 'binary.AtEnd { Write $system.Encryption.Base64Encode(binary.Read(.len),'..Base64LineBreaks) } } Else { Write $system.Encryption.Base64Encode(binary,'..Base64LineBreaks) }
If ..OutputDestination'="device" { Use io }
Set ..IndentNext=0
Quit $$$OK}- Log in to post comments
