matchlen := 0;
end;
{******************************** interface procedures ************************}
procedure lhacompress(instr, outstr: tstream);
begin
initmemory;
try
infile := instr;
outfile := outstr;
origsize := infile.size - infile.position;
compsize := 0;
outfile.write(origsize,4);
encode;
finally
freememory;
end;
end;
procedure lhaexpand(instr, outstr: tstream); //解码
begin
try
initmemory;
infile := instr;
outfile := outstr;
compsize := infile.size - infile.position;
infile.read(origsize,4);
decode;
finally
freememory;
end;
end;
initialization
clen := nil;
ctable := nil;
right := nil;
left := nil;
buffer := nil;
heap := nil;
end.
{******************************** test program ********************************}
{
the following simple program can be used for testing the lh5unit.
it compresses/expands files compatible with lharc.
}
program testlh5;
uses
wincrt,
sysutils,
classes,
lh5unit;
var
instr, outstr: tfilestream;
begin
if not (paramcount in [2..3]) then
begin
writeln('usage :');
writeln('to compress infile into outfile : lh5 infile outfile');
writeln('to expand infile into outfile : lh5 infile outfile e');
halt;
end;
instr := tfilestream.create(paramstr(1),fmopenread);
outstr := tfilestream.create(paramstr(2),fmcreate);
if paramcount=2 then
lhacompress(instr, outstr)
else
lhaexpand(instr, outstr);
instr.free;
outstr.free;
end.