Delphi有一个zlib.dcu库,专用来压缩文件!
program MyZip;
uses
Windows, Zlib, Classes, SysUtils;
{$R *.RES}
var inF, ouF, zpF: TStream;
buf: array[1..1024]of char;
i: integer;
begin
inF:=TFileStream.Create('Papper.ini', fmOpenRead);
ouF:=TFileStream.Create('Papper.Z', fmCreate);
zpF:=TCompressionStream.Create(clDefault, ouF);
zpF.CopyFrom(inF, 0);
zpF.Free;
inF.Free;
ouF.Free;
inF:=TFileStream.Create('Papper.Z', fmOpenRead);
ouF:=TFileStream.Create('Papper.txt', fmCreate);
zpF:=TDecompressionStream.Create(inF);
i:=zpF.Read(buf, 1024);
while i>0 do begin
ouF.Write(buf, i);
i:=zpF.Read(buf, 1024);
end;
ouF.Free;
zpF.Free;
inF.Free;
end.
此程序将Papper.ini 压缩-> Papper.Z 解压缩->Papper.txt
但是算法与WinZip不兼容,及时加入zip的头文件,用WinZip也解不开。
不知哪位大侠有高招,说来听听!