mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-28 18:21:00 +02:00
+ New example for base64 encoding
This commit is contained in:
parent
072f6e4ec6
commit
c7c5594bcd
39
fcl/tests/b64.pp
Normal file
39
fcl/tests/b64.pp
Normal file
@ -0,0 +1,39 @@
|
||||
{$mode objfpc}
|
||||
{$h+}
|
||||
program b64;
|
||||
|
||||
uses classes,base64;
|
||||
|
||||
Function EncodeBase64(S : String) : String;
|
||||
|
||||
Var
|
||||
S1,S2 : TStringStream;
|
||||
|
||||
begin
|
||||
S1:=TStringStream.Create(S);
|
||||
Try
|
||||
S1.Position:=0;
|
||||
S2:=TStringStream.Create('');
|
||||
Try
|
||||
With TBase64EncodingStream.Create(S2) do
|
||||
Try
|
||||
CopyFrom(S1,S1.Size);
|
||||
Finally
|
||||
Free;
|
||||
end;
|
||||
Result:=S2.DataString;
|
||||
finally
|
||||
S2.Free;
|
||||
end;
|
||||
finally
|
||||
S1.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
Var
|
||||
S : String;
|
||||
|
||||
begin
|
||||
S:='String to be encoded';
|
||||
Writeln('"',S,'" -> "',EncodeBase64(S),'"');
|
||||
end.
|
Loading…
Reference in New Issue
Block a user