program TestProject; {$APPTYPE CONSOLE} {$R *.res} {$DEFINE INC_FROM_FILE} uses System.SysUtils, System.Classes, System.Zip; { LZ Data } {$IFDEF INC_FROM_FILE} {$INCLUDE 'include_me.inc'} {$ELSE} const buffer_size = 2; const buffer: array[0..1] of Byte = ($00, $00); {$ENDIF} type TLZBin = class(TObject) private PMem : TMemoryStream; PZip : TZipFile; public constructor Create(BaseAddr: Pointer; BufferSize: Int64); destructor Destroy; override; function HaveFile(FileName: string): Boolean; function FileToStream(FileName: string; WriteToStream: TStream): Boolean; end; { TLZBin } constructor TLZBin.Create(BaseAddr: Pointer; BufferSize: Int64); begin inherited Create(); PMem := TMemoryStream.Create; PMem.SetSize(BufferSize); Move(BaseAddr^, PMem.Memory^, BufferSize); PZip := TZipFile.Create(); PZip.Open(PMem, zmRead); end; destructor TLZBin.Destroy; begin FreeAndNil(PZip); FreeAndNil(PMem); inherited; end; function TLZBin.FileToStream(FileName: string; WriteToStream: TStream): Boolean; var DecompressionStream: TStream; LocalHeader: TZipHeader; begin Result := False; Assert(Assigned(WriteToStream), '2nd param must be defined first'); PZip.Read(FileName, DecompressionStream, LocalHeader); try WriteToStream.CopyFrom(DecompressionStream, DecompressionStream.Size); Result := True; finally DecompressionStream.Free; end; end; function TLZBin.HaveFile(FileName: string): Boolean; begin Result := PZip.IndexOf(FileName) > -1; end; { $EXE } var lz: TLZBin; file_contents: TStringStream; begin try lz := TLZBin.Create(@buffer[0], buffer_size); try if lz.HaveFile('Resources/Kbits.txt') then begin Writeln('File Exists, unpacking...'); // read an file file_contents := TStringStream.Create(); try lz.FileToStream('Resources/Kbits.txt', file_contents); file_contents.Seek(0,0); Writeln(file_contents.ReadString(file_contents.Size)); finally FreeAndNil(file_contents); end; // end of read end else Writeln('File Not Exists'); finally FreeAndNil(lz); end; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.