Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Reading data from gz-file in XE8



Permlink Replies: 1 - Last Post: Sep 9, 2015 8:47 AM Last Post By: Ole Rössel
Ole Rössel

Posts: 3
Registered: 4/9/98
Reading data from gz-file in XE8
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 4, 2015 7:19 AM
In Delphi 7 I have used zlib with code like this

uses gzio, ...;

InFileGz:=gzopen(FileName,'r',0);
repeat
buf:=gzgets(InFileGz,PChar(Buf),BufLen);
// do something with Buf here
until gzeof(InFileGz);
gzclose(InFileGz);

This works fine and fast and is not memory consuming.

I have tried to use the same construct in XE8 and failed.
Maybe its because the primitives like gzgets is not available
in the XE8 implementation of Zlib.
They are labeled "For internal use only" in the help file.

Instead I have used the following algorithm using streams:

begin
CompressedFile:=TFileStream.Create(InFileName,fmOpenRead);
DeCompressor:=TDecompressionStream.Create(CompressedFile,15+16);

repeat
nRead:=DeCompressor.Read(Buffer,SizeOf(Buffer));
StrBuffer:=StrBuffer+string(Buffer);

StartIndex:=PosEx('<'>',StrBuffer,StartIndex);
while (StopIndex > 0) and (StartIndex < StopIndex) do
begin
Msg:=Trim(System.Copy(StrBuffer,StartIndex,StopIndex));
System.Delete(StrBuffer,1,StopIndex);
if IsValidMsgType(Msg)
then SourceList.Add(Msg);
StartIndex:=PosEx('<',StrBuffer);
StopIndex:=PosEx('>',StrBuffer);
end;

until nRead = 0;
FreeAndNil(CompressedFile);
FreeAndNil(DeCompressor);
end;

This algorithm works and I get what I want in the Msg string
but it is extreamly slow and memory consuming for large files.

Is there a faster way to read data from a gz-file that may be used in XE8?

Edited by: Ole Rössel on Sep 4, 2015 7:30 AM
Ole Rössel

Posts: 3
Registered: 4/9/98
Re: Reading data from gz-file in XE8
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 9, 2015 8:47 AM   in response to: Ole Rössel in response to: Ole Rössel
Problem solved...

Ole Rössel wrote:
In Delphi 7 I have used zlib with code like this

uses gzio, ...;

InFileGz:=gzopen(FileName,'r',0);
repeat
buf:=gzgets(InFileGz,PChar(Buf),BufLen);
// do something with Buf here
until gzeof(InFileGz);
gzclose(InFileGz);

This works fine and fast and is not memory consuming.

I have tried to use the same construct in XE8 and failed.
Maybe its because the primitives like gzgets is not available
in the XE8 implementation of Zlib.
They are labeled "For internal use only" in the help file.

Instead I have used the following algorithm using streams:

begin
CompressedFile:=TFileStream.Create(InFileName,fmOpenRead);
DeCompressor:=TDecompressionStream.Create(CompressedFile,15+16);

repeat
nRead:=DeCompressor.Read(Buffer,SizeOf(Buffer));
StrBuffer:=StrBuffer+string(Buffer);

StartIndex:=PosEx('<'>',StrBuffer,StartIndex);
while (StopIndex > 0) and (StartIndex < StopIndex) do
begin
Msg:=Trim(System.Copy(StrBuffer,StartIndex,StopIndex));
System.Delete(StrBuffer,1,StopIndex);
if IsValidMsgType(Msg)
then SourceList.Add(Msg);
StartIndex:=PosEx('<'>',StrBuffer);
end;

until nRead = 0;
FreeAndNil(CompressedFile);
FreeAndNil(DeCompressor);
end;

This algorithm works and I get what I want in the Msg string
but it is extreamly slow and memory consuming for large files.

Is there a faster way to read data from a gz-file that may be used in XE8?

Edited by: Ole Rössel on Sep 4, 2015 7:30 AM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02