How to read from large files.
Files can be read from their current position or from a specified position. The procedure is the same in both cases:
Example
Modify applications to handle reads beyond 2GB–1. For example, a counter variable accumulating the number of bytes should be of type TInt64. The counter variable bytesRead in the example below is now a TInt64.
// RFile file; RFile64 file; TInt err = file.Open(TheFs, _L(“BIGFILE.BIG”), EFileRead); if(err != KErrNone) { // handle unrelated error return err; } // Large file access is now supported! // Replace TInt variable with TInt64 variable // Tint bytesRead = 0; TInt64 bytesRead = 0; TBuf8<4096> readBuf; ... // Read loop FOREVER { // Read a block r = file.Read(readBuf); if(KErrNone != r) { // Error handling break; } bytesRead += readBuf.Length(); // bytesRead can exceed 2G as large files are now supported
Example
To read locations beyond 2GB–1 in large files the file must be opened for 64-Bit access and the TInt variable should be replaced with a TInt64 variable or specify the position value directly.
// RFile file; RFile64 file; TInt err = file.Open(TheFs, _L(“BIGFILE.BIG”), EFileRead); if(err != KErrNone) { // handle unrelated error return err; } // Large file access is now supported! // TInt readPosition = 0; TInt64 readPosition = 0; // Use a TInt64 to prevent wrap-around TBuf8<4096> readBuf; ... // Read loop FOREVER { // Read a block r = file.Read(readPosition, readBuf); if(KErrNone != r) { // Error handling break; } readPosition += readBuf.Length(); // Must use TInt64 read position }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.