Seeking a Position in a Large File

How to seek a particular position in a large file.

The function RFile64::Seek() is the 64-bit version of RFile::Seek(). The Seek() function can modify the file pointer to point to any position addressable by the aPos parameter.

See RFile64::Seek(TSeek aMode, TInt64& aPos).

To get the current position of the file pointer, use the TSeek mode ESeekCurrent. The function updates the output parameter with the new file pointer position in 64-bits.

Different modes of operation can be specified. These modes are defined by TSeek.

  1. Use TInt64 instead of TInt for the offset from the location specified in aMode.
    // Remove TInt filePosition = 0;
    TInt64 filePosition = 0;
  2. To retrieve the current position of the file pointer in a large file use RFile::Seek64() with the mode ESeekCurrent.
    TInt64 filePosition = 0;
    // Remove r = file.Seek(ESeekCurrent, filePosition);
    r = file.Seek64(ESeekCurrent, filePosition);
  3. To set the file pointer to a particular position within a large file use RFile::Seek64() with the seek mode ESeekStart and a seek position value that is of type TInt64.
    TInt64 seekPos = 3000000000;
    // Remove r = file.Seek(ESeekStart, seekPos);
    r = file.Seek64(ESeekStart, seekPos);

Seek position example

If a large file seek is required, use RFile64::Seek() instead of RFile::Seek() and use a TInt64 value to specify the location.

    // RFile file;
    RFile64 file;
    TInt err = file.Open(TheFs, _L(“BIGFILE.BIG”), EFileWrite);
    if(err != KErrNone)
        {
        // unrelated error
        return err;
        }

    // Large file access is now supported!
    // TInt seekPos = 0;
    Tint64 seekPos = 0;

    // Seek the current position. This can be greater than 2GB.
    err = file.Seek(ESeekEnd, seekPos);
    if(err != KErrNone)
        {
        return err;
        }