-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path01_compress_easy.dpr
More file actions
83 lines (75 loc) · 2.36 KB
/
Copy path01_compress_easy.dpr
File metadata and controls
83 lines (75 loc) · 2.36 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(*
* xz-examples-delphi
* Copyright (C) 2015-2020 Vincent Hardy <vincent.hardy@linuxunderground.be>
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version
* 3.0 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, see
* https://www.gnu.org/licenses/.
*)
// Compress from stdin to stdout in multi-call mode
//
// Usage: 01_compress_easy PRESET < INFILE > OUTFILE
//
// Example: 01_compress_easy 6 < foo > foo.xz
{$APPTYPE CONSOLE}
program compress_easy;
uses
SysUtils, Windows, Classes,
LibLZMA, XZ;
procedure show_usage_and_exit;
begin
writeln(ErrOutput,'Usage: '+paramstr(0)+' PRESET < INFILE > OUTFILE');
writeln(ErrOutput,'PRESET is a number 0-9 and can optionally be followed by ''e'''+
' to indicate extreme preset');
halt(1);
end;
function get_preset:Cardinal;
begin
// One argument whose first char must be 0-9.
if (paramcount<>1) or (paramstr(1)[1]<'0') or (paramstr(1)[1]>'9')
then
show_usage_and_exit;
// Calculate the preste level 0-9.
result:=ord(paramstr(1)[1])-48;
// If there is a second char, it must be 'e'. It will set
// the LZMA_PRESET_EXTREME flag.
if length(paramstr(1))>1 then
begin
if (paramstr(1)[2]<>'e') and (length(paramstr(1))<>2)
then
show_usage_and_exit
else
result:=result or LZMA_PRESET_EXTREME;
end;
end;
var
StdIn,StdOut:THandleStream;
Comp: TXZCompressionStream;
preset:Cardinal;
begin
if LoadLZMADLL then
begin
preset:=get_preset;
StdIn := THandleStream.Create(GetStdHandle(STD_INPUT_HANDLE));
StdOut := THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE));
Comp := TXZCompressionStream.Create(StdOut, preset, LZMA_CHECK_CRC64);
try
Comp.CopyFrom(StdIn, 0);
finally
Comp.Free;
StdIn.Free;
StdOut.Free;
end;
UnloadLZMADLL;
end else
raise Exception.CreateFmt('%s not found.',[LZMA_DLL]);
end.