[fpc-devel] TFileStream problem with bigger file (> GB)?

Martin fpc at mfriebe.de
Wed Mar 10 02:53:18 CET 2010


I have a strange issue with TFileStream, just wondering if anything is 
known...

The function below is supposed to read the first (up to) 5000 bytes of a 
file. It works fine on "normal" sized files.

But I have a couple of files between 3 and 8 GB in size, and for those 
files read just returns buf filled with zeros.
The output shows, that fs.read returns 5000, that is it claims that the 
full amount has been read.
Smaller files on the same filesystem do work. there are no spaces in the 
filename or directory.

This happens on windows, fpc from trunc (older and today).

> function TFileInfo.GetChecksum: Integer;
> const
>   PRE_READ_SIZE = 5000;
> var
>   c, i: Integer;
>   fs: TFileStream;
>   buf: Array [0..PRE_READ_SIZE] of Byte;
> begin
>   if FChecksumDone then exit(FChecksum);
>   c := 0;
>   try
>     fs := TFileStream.Create(Dir + Name, fmOpenRead);
>     try
> debugln(['## ',
>       fs.Read(buf[0], PRE_READ_SIZE)
> ]);
>       for i := 0 to PRE_READ_SIZE - 1 do begin
>         c := c + buf[i];
>         if i > 0 then
>           c := (c + (buf[i] * buf[i-1])) AND $7fffff;
>       end;
>     finally
>       fs.free;
>     end;
>   except
>   end;
> debugln(['--- ',Name,' ',c]);
>   FChecksum := c;
>   FChecksumDone := True;
>   Result := FChecksum;
> end;




More information about the fpc-devel mailing list