-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathSimpleEncoder.dpr
More file actions
58 lines (54 loc) · 1.28 KB
/
SimpleEncoder.dpr
File metadata and controls
58 lines (54 loc) · 1.28 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
program SimpleEncoder;
{$APPTYPE CONSOLE}
uses
Windows, SysUtils, clEncoder, Classes;
function GetMethod(const AMethod: string): TclEncodeMethod;
begin
if (AMethod = 'QP') or (AMethod = 'Q') then
begin
Result := cmQuotedPrintable;
end else
if (AMethod = 'BASE64') or (AMethod = 'B') then
begin
Result := cmBase64;
end else
if (AMethod = 'UUE') or (AMethod = 'U') then
begin
Result := cmUUEncode;
end else
begin
Result := cmNone;
end;
end;
var
Encoder: TclEncoder;
Src, Dst: TStream;
ch: Char;
begin
if ParamCount < 4 then
begin
WriteLn('This console app encodes / decodes files in Base64, Quoted-Printable, and UUEncode formats.');
WriteLn('Usage: Encoder.exe srcfile destfile operation[E][D] method[QP][BASE64][UUE]');
WriteLn('Press Enter to continue...');
Read(ch);
Exit;
end;
Encoder := nil;
Src := nil;
Dst := nil;
try
Encoder := TclEncoder.Create(nil);
Src := TFileStream.Create(ParamStr(1), fmOpenRead);
Dst := TFileStream.Create(ParamStr(2), fmCreate);
Encoder.EncodeMethod := GetMethod(ParamStr(4));
if (ParamStr(3) = 'E') then
Encoder.Encode(Src, Dst)
else
Encoder.Decode(Src, Dst);
WriteLn('Done.');
finally
Dst.Free();
Src.Free();
Encoder.Free();
end;
end.