需要引入system.ZLib包

procedure TFormMain1.Button25Click(Sender: TObject);   //压缩
var
  LInput, LOutput: TFileStream;
  LZip: TZCompressionStream;
begin
  inherited;
  LInput := TFileStream.Create(Edit2.Text, fmOpenRead);   //需要压缩的文件
  LOutput := TFileStream.Create(Edit3.Text + '.zip', fmCreate);  //压缩完成的文件
  LZip := TZCompressionStream.Create(LOutput);

  LZip.CopyFrom(LInput, LInput.Size);

  LZip.Free;
  LInput.Free;
  LOutput.Free;

end;

procedure TFormMain1.Button26Click(Sender: TObject);   //解压
var
  LInput, LOutput: TFileStream;
  LUnZip: TZDecompressionStream;

begin
  { Create the Input, Output, and Decompressed streams. }
  LInput := TFileStream.Create(Edit2.Text, fmOpenRead);  //解压的文件
  LOutput := TFileStream.Create(ChangeFileExt(Edit3.Text, '.txt'), fmCreate);  //解压后的文件
  LUnZip := TZDecompressionStream.Create(LInput);

  { Decompress data. }
  LOutput.CopyFrom(LUnZip, 0);

  { Free the streams. }
  LUnZip.Free;
  LInput.Free;
  LOutput.Free;
end;

 

相关文章:

  • 2021-06-27
  • 2022-12-23
  • 2021-07-15
  • 2022-01-23
  • 2021-10-05
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-17
  • 2021-11-05
  • 2022-01-27
  • 2022-12-23
  • 2021-08-10
  • 2021-10-10
相关资源
相似解决方案