![]() |
|
#6
|
|||
|
|||
![]() Код из моего проекта:
Код:
unit ZLibUtils; interface uses Windows, SysUtils, Classes, ZLib; function ExpandFile(ASourceFile, ATargetFile : String) : Boolean; function CompressFile(ASourceFile, ATargetFile : String) : Boolean; implementation const BUF_SIZE = 512; function ExpandFile(ASourceFile, ATargetFile : String) : Boolean; var ACount : Integer; AZLib : TDeCompressionStream; ASource, ATarget : TFileStream; ABuf : Array [1..BUF_SIZE] Of Char; begin Result := False; If FileExists(ASourceFile) Then Try ASource := TFileStream.Create(ASourceFile,fmOpenRead); Try ATarget := TFileStream.Create(ATargetFile,fmCreate Or fmShareExclusive); Try AZLib := TDeCompressionStream.Create(ASource); Try Repeat ACount := AZLib.Read(ABuf,BUF_SIZE); ATarget.Write(ABuf,ACount); Until ACount < BUF_SIZE; Result := True; Finally AZLib.Free; End; Finally ATarget.Free; End; Finally ASource.Free; End; Except // Hide all exceptions End; end; function CompressFile(ASourceFile, ATargetFile : String) : Boolean; var ACount : Integer; AZLib : TCompressionStream; ASource, ATarget : TFileStream; ABuf : Array [1..BUF_SIZE] Of Char; begin Result := False; If FileExists(ASourceFile) Then Try ASource := TFileStream.Create(ASourceFile,fmOpenRead); Try ATarget := TFileStream.Create(ATargetFile,fmCreate Or fmShareExclusive); Try AZLib := TCompressionStream.Create(clMax,ATarget); Try Repeat ACount := ASource.Read(ABuf,BUF_SIZE); AZLib.Write(ABuf,ACount); Until ACount < BUF_SIZE; Result := True; Finally AZLib.Free; End; Finally ATarget.Free; End; Finally ASource.Free; End; Except // Hide all exceptions End; end; end. |