1
0
mirror of synced 2024-12-22 17:23:07 +01:00

Added: XMLDataBindingUtils Base64 helpers for loading from stream/file

This commit is contained in:
Mark van Renswoude 2014-08-25 18:23:03 +00:00
parent 2ff0f544d3
commit cc719caf0c

View File

@ -85,10 +85,12 @@ const
{ Now wraps the JclMime implementation: { Now wraps the JclMime implementation:
Lightening fast Mime (Base64) Encoding and Decoding routines. Lightening fast Mime (Base64) Encoding and Decoding routines.
Coded by Ralf Junker (ralfjunker@gmx.de).} Coded by Ralf Junker (ralfjunker@gmx.de).}
function Base64Encode(AValue: String): String; function Base64Encode(AValue: String): string;
function Base64Decode(AValue: String): String; function Base64Decode(AValue: String): string;
procedure Base64DecodeToStream(AValue: String; AStream: TStream); function Base64EncodeFromStream(AStream: TStream): string;
procedure Base64DecodeToFile(AValue: String; const AFileName: String); function Base64EncodeFromFile(const AFileName: string): string;
procedure Base64DecodeToStream(AValue: string; AStream: TStream);
procedure Base64DecodeToFile(AValue: string; const AFileName: string);
const const
XMLSchemaInstanceURI = 'http://www.w3.org/2001/XMLSchema-instance'; XMLSchemaInstanceURI = 'http://www.w3.org/2001/XMLSchema-instance';
@ -401,6 +403,35 @@ begin
end; end;
function Base64EncodeFromStream(AStream: TStream): string;
var
output: TStringStream;
begin
output := TStringStream.Create('');
try
MimeEncodeStream(AStream, output);
Result := output.DataString;
finally
FreeAndNil(output);
end;
end;
function Base64EncodeFromFile(const AFileName: string): string;
var
input: TFileStream;
begin
input := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyWrite);
try
Result := Base64EncodeFromStream(input);
finally
FreeAndNil(input);
end;
end;
procedure Base64DecodeToStream(AValue: String; AStream: TStream); procedure Base64DecodeToStream(AValue: String; AStream: TStream);
var var
input: TStringStream; input: TStringStream;
@ -417,20 +448,14 @@ end;
procedure Base64DecodeToFile(AValue: String; const AFileName: String); procedure Base64DecodeToFile(AValue: String; const AFileName: String);
var var
input: TStringStream;
output: TFileStream; output: TFileStream;
begin begin
input := TStringStream.Create(AValue); output := TFileStream.Create(AFileName, fmCreate or fmShareDenyWrite);
try try
output := TFileStream.Create(AFileName, fmCreate or fmShareDenyWrite); Base64DecodeToStream(AValue, output);
try
MimeDecodeStream(input, output);
finally
FreeAndNil(output);
end;
finally finally
FreeAndNil(input); FreeAndNil(output);
end; end;
end; end;