{ %skiptarget=os2,emx } (* This test program tries to link in a resource file in MS Windows format *) (* which is not supported for the OS2 and EMX targets. *) program bunzip2test; { This file is part of the Free Pascal packages. Copyright (c) 1999-2012 by the Free Pascal development team Tests bzip2 decompression. See the file COPYING.FPC, included in this distribution, for details about the copyright. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. **********************************************************************} {$mode objfpc}{$h+} uses SysUtils, classes, bzip2stream, md5; // Uses new bunzip2 code (using classes, not objects) to test decompression of a bzip2 compressed file. {$R testbzip2.res} //contains readme.txt.bz2 //Change this whenever you change the test resource: const ExpectedHash='4ab247ef61f1f9a6fec26493aab823cd'; function Decompress(SourceFile, TargetFile: string): boolean; var InFile:TFileStream; Decompressed:TDecompressBzip2Stream; OutFile:TFileStream; Buffer: Pointer; i: integer; const buffersize=$2000; begin result:=false; //fail by default InFile:=TFileStream.Create(SourceFile, fmOpenRead); try Decompressed:=TDecompressBzip2Stream.Create(InFile); OutFile:=TFileStream.Create(TargetFile, fmCreate); try //We don't have seek on the TDecompressBzip2stream, so can't use //CopyFrom... //Decompressed.CopyFrom(InFile, InFile.Size); GetMem(Buffer,BufferSize); repeat i:=Decompressed.Read(buffer^,BufferSize); if i>0 then OutFile.WriteBuffer(buffer^,i); until iEmptyStr then DeleteFile(CompressedFile); if UncompressedFile<>EmptyStr then DeleteFile(UncompressedFile); finally // Ignore errors; operating system should clean out temp files end; end; Halt(code); end.