function
UnZipCofing(Fname:
string
):
string
;
var
ds: TDecompressionStream;
ms, fs, tmpfs: TMemoryStream;
ss: TStringStream;
bufferSize, blockSize, nextOff:
LongWord
;
begin
fs := TMemoryStream
.
Create;
tmpfs := TMemoryStream
.
Create;
ms := TMemoryStream
.
Create;
ss := TStringStream
.
Create(
''
);
if
not
FileExists(Fname)
then
begin
ShowMessage(
'文件不存在!'
);
exit;
end
;
try
fs
.
LoadFromFile(Fname);
nextOff :=
60
;
while
nextOff >
0
do
begin
fs
.
Seek(nextOff, soFromBeginning);
//读取缓冲区大小
fs
.
Read(bufferSize, SizeOf(bufferSize));
bufferSize := Swap32(bufferSize);
//读取压缩块大小
fs
.
Read(blockSize, SizeOf(blockSize));
blockSize := Swap32(blockSize);
//读取下一块位置
fs
.
Read(nextOff, SizeOf(nextOff));
nextOff := Swap32(nextOff);
//复制压缩数据块到临时数据流
tmpfs
.
Clear;
tmpfs
.
CopyFrom(fs, blockSize);
tmpfs
.
Position :=
0
;
//解压数据块
ds := TDecompressionStream
.
Create(tmpfs);
ms
.
SetSize(bufferSize);
ZeroMemory(ms
.
Memory, bufferSize);
ms
.
Position :=
0
;
ds
.
Read(ms
.
Memory^, bufferSize);
//将解压后的数据流复制到字符串数据流
ss
.
CopyFrom(ms,
0
);
ds
.
Free;
end
;
{end while}
//输出合并后的字符串流。
Result := ss
.
DataString;
finally
//垃圾回收
fs
.
Free;
tmpfs
.
Free;
ms
.
Free;
ss
.
Free;
end
;
end
;