Delphi Zlib 压缩数据流解压通用函数

这段代码展示了如何使用Zlib库通过流存储进行数据解压缩。它创建了一个TDecompressionStream对象,从输入流读取压缩数据,并将解压缩的数据写入输出流。

  用 Zlib 压缩数据, 通过流存储,可以使用下面函数实现解压:

function UnZipStream(Input, Output: TStream; var Buf: PByte): Boolean;
var
  DS: TDecompressionStream;
  nBufSize: Integer;
begin
  Result := False;
  if Assigned(Input) and Assigned(Output) then
  begin
    Input.Position := 0;
    Output.Position := 0;
    DS := TDecompressionStream.Create(Input);
    try
      nBufSize := DS.Read(Buf^, ZIP_MAX_BUF_SIZE);
      while nBufSize > 0 do
      begin
        Output.Write(Buf^, nBufSize);
        nBufSize := DS.Read(Buf^, ZIP_MAX_BUF_SIZE);
      end;
      if Output.Position > 0 then
      begin
        Result := true;
        Exit;
      end;
    finally
      DS.Free;
    end;
  end;
end;

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值