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

被折叠的 条评论
为什么被折叠?



