How to write to large files.
There are four RFile::Write() overloaded functions relative/current position that allow you to specify a position greater than 2GB–1 by using the TInt64 parameter.
The migration procedure is as follows:
Example
The example below shows an application writing to locations greater than 2GB–1. The RFile class has been replaced with RFile64 and the TInt variable that represents the number of bytes written has been changed to TInt64.
// RFile file; RFile64 file; TInt err = file.Open(TheFs, _L(“BIGFILE.BIG”), EFileWrite); if(err != KErrNone) { // unrelated error return err; } // Tint bytesWritten = 0; Tint64 bytesWritten = 0; TBuf8<1024> writeBuf; ... FOREVER { // Fill buffer with input data r = prepareBuffer(writeBuf); if(KErrNone != r) { // No data to write! break; } r = file.Write(writeBuf); if(r != KErrNone) { // Error handling } bytesWritten += writeBuf.Length(); }
There are four RFile::Write() overloaded functions that allow you to specify an absolute position greater than 2GB–1 by using the TInt64 parameter.
RFile64::Write(TInt64 aPos, const TDesC8& aDes, TRequestStatus& aStatus)
RFile64::Write(TInt64 aPos, const TDesC8& aDes, TInt aLength)
RFile64::Write(TInt64 aPos, const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus).
The migration procedure is as follows:
Example
To write to locations beyond 2GB–1 the file must be opened for 64-bit access and TInt variables should be replaced with TInt64.
// RFile file; RFile64 file; TInt err = file.Open(TheFs, _L(“BIGFILE.BIG”), EFileWrite); if(err != KErrNone) { // unrelated error return err; } // TInt writePosition = 0; TInt64 writePosition = 0; // Use a TInt64 to prevent wrap-around TBuf8<1024> writeBuf; ... FOREVER { // Fill buffer with input data r = prepareBuffer(writeBuf); if(KErrNone != r) { // No data to write! break; } r = file.Write(writePosition, writeBuf); if(r != KErrNone) { // unrelated error return r; } writePosition += writeBuf.Length(); // Must use a TInt64 }
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.