summaryrefslogtreecommitdiff
path: root/packages/fcl-base/examples/b64.pp
blob: c4483a4fdf83274cbb01e6c4e793f032130413a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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.