OmniXML项目中的OmniXMLUtils.pas包含以下函数:
function Base64Decode(encoded, decoded: TStream): boolean; overload;
function Base64Decode(const encoded: string; decoded: TStream): boolean; overload;
function Base64Decode(const encoded: string; var decoded: string): boolean; overload;
function Base64Decode(const encoded: string): string; overload;
procedure Base64Encode(decoded, encoded: TStream); overload;
procedure Base64Encode(decoded: TStream; var encoded: string); overload;
function Base64Encode(decoded: TStream): string; overload;
function Base64Encode(const decoded: string): string; overload;
procedure Base64Encode(const decoded: string; var encoded: string); overload;
Base64Decode(string, TStream) 应该可以解决问题。对于 TStream 参数,您可以像这样传递 TFileStream :
procedure SaveBase64ToFile(const encoded, fileName: string);
var
fs: TFileStream;
begin
fs := TFileStream.Create(fileName, fmCreate);
try
if not Base64Decode(encoded, fs) then
raise Exception.Create('Invalid data!');
finally FreeAndNil(fs); end;
end;