【Delphi】压缩解压缩zip文件,包含密码功能

        在Delphi开发中,我们经常需要使用压缩和解压缩功能,Delphi自带的system.zip 单元,完全支持文件、内存流的压缩和解压缩。可是一直不能完整的支持带有密码的压缩和解压缩,好在有大佬做好了,我们拿来使用就是了。

        具体的下载地址如下:

        GitHub - UweRaabe/EncryptedZipFile: TZipFile with Password Encryption

下载下来后有三个文件,具体如下:

PKWAREZipCryptor.pas

Add PKWARE Zip implementation of IZipCryptor for Delphi 12

支持D12版本

uEncryptedZipFile.pas

Add support for Delphi 11.1 and 11.2

支持D11版本

uEncryptedZipFileRO.pas

initial commit

原始发布,低版本

如何使用呢?

一、Delphi 12版本使用方法

需要引用:PKWAREZipCryptor.pas 文件。

uses
    PKWAREZipCryptor.pas,
    ....;

var
  LZipFile: TZipFile;
  

begin
  //创建压缩对象
  LZipFile := TZipFile.Create;
  LZipFile.Cryptor := TPKWAREZipCryptor.Create;
  LZipFile.Password := password;
  ....

end

二、Delphi 11.1 和 11.2 使用方法

需要引用:uEncryptedZipFile.pas 文件。

uses
  uEncryptedZipFile,
  ....;

var
  LZipFile: TEncryptedZipFile;
     

begin
  //创建压缩对象
  LZipFile := TEncryptedZipFile.Create(password);
  LZipFile.Password := password;
  .....

end  

三、兼容D12 和D11.1 D11.2 的封装函数

//压缩一个目录到一个文件中,包含密码
//ZipDir: 表示需要压缩的目录,  ZipFileName:压缩后的zip文件名称  password:密码
function ZipDir2File(const ZipDir, ZipFileName : String; const password : string = ''; Compression: TZipCompression = zcDeflate; ZipProgress: TZipProgressEvent = nil) : Boolean;

//解压一个zip文件到一个指定的目录中,包含压缩文件的目录结构
//ZipFileName:需要解压的zip文件名称,  UnZipDir:解压后需要放置的目录   password:密码
function UnZipFile2Dir(const ZipFileName, UnZipDir : String; const password : string = ''; ZipProgress: TZipProgressEvent = nil) : Boolean;


//将zip压缩文件中的一个文件加压成字节流
procedure ExtractFile_Bytes(const ZipFileName : string; const FileName,password : string; var B : TBytes);

//将zip压缩文件中的一个文件加压成字Stream,这样就很容易实现保存成一个文件
procedure ExtractFile_Stream(const ZipFileName : string; const FileName,password : string; var ST : TStream);

以上函数兼容两个版本,直接使用。

源程序下载(收费)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海纳老吴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值