diff -r 4816d766a08a -r f345bda72bc4 Symbian3/PDK/Source/GUID-D71D0091-5C4E-5B2F-B1B6-783F11AB5021.dita --- a/Symbian3/PDK/Source/GUID-D71D0091-5C4E-5B2F-B1B6-783F11AB5021.dita Tue Mar 30 11:42:04 2010 +0100 +++ b/Symbian3/PDK/Source/GUID-D71D0091-5C4E-5B2F-B1B6-783F11AB5021.dita Tue Mar 30 11:56:28 2010 +0100 @@ -1,83 +1,119 @@ - - - - - -Writing to Large Files This tutorial shows how to write to large files.
Introduction

Files can be written to their current position or from a specified position, as discussed here:

  • Write() with relative/current position

  • Write() with absolute position.

Write() with relative/current position

There are four RFile::Write overload functions relative/current position that allow you to specify a position greater than 2GB–1 by using the TInt64 parameter.

  • RFile64::Write(const TDesC8& aDes)

  • RFile64::Write(const TDesC8& aDes, - TRequestStatus& aStatus)

  • RFile64::Write(const TDesC8& aDes, TInt - aLength)

  • RFile64::Write(const TDesC8& aDes, TInt aLength, - TRequestStatus& aStatus).

  1. Use RFile64 instead of RFile.

    // RFile file; -RFile64 file;

  2. Use TInt64 variables in place of TInt variables where they may represent the number of bytes written.

    // Tint bytesWritten = 0; -Tint64 bytesWritten = 0;

Write with relative/current position 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) - { - // We will only get here if a real error condition occurs. - 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(); - }
Write() with absolute position

There are four RFile::Write overload functions with absolute position that allow you to specify a position greater than 2GB–1 by using the TInt64 parameter.

  • RFile64::Write(TInt64 aPos, const TDesC8& - aDes)

  • 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).

  1. Use a TInt64 instead of a TInt for the write position.

    // TInt writePosition = 0; - TInt64 writePosition = 0;

  2. Replace RFile with RFile64.

    // RFile file; - RFile64 file;

Write with absolute position 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) - { - // We will only get here for upon encountering a real error condition. - 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) - { - // We will only get here upon encountering a real error condition. - return r; - } - writePosition += writeBuf.Length(); // Must use a TInt64 - }
\ No newline at end of file + + + + + +Writing +to Large Files How to write to large files. +
Write() from relative/current position

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.

    +
  • RFile64::Write(const +TDesC8& aDes)

  • +
  • RFile64::Write(const +TDesC8& aDes, TRequestStatus& aStatus)

  • +
  • RFile64::Write(const +TDesC8& aDes, TInt aLength)

  • +
  • RFile64::Write(const +TDesC8& aDes, TInt aLength, TRequestStatus& aStatus).

  • +

The migration procedure is as follows:

    +
  1. Use RFile64 instead +of RFile.

    // RFile file; +RFile64 file;

  2. +
  3. Use TInt64 variables +in place of the TInt variables representing the number +of bytes written.

    // Tint bytesWritten = 0; +Tint64 bytesWritten = 0;

  4. +

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(); + }
+
Write() from absolute position

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)

  • +
  • 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:

    +
  1. Use a TInt64 instead +of a TInt for the write position.

    // TInt writePosition = 0; + TInt64 writePosition = 0;

  2. +
  3. Replace RFile with RFile64.

    // RFile file; + RFile64 file;

  4. +

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 + }
+
\ No newline at end of file