Symbian3/PDK/Source/GUID-D71D0091-5C4E-5B2F-B1B6-783F11AB5021.dita
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Tue, 30 Mar 2010 11:56:28 +0100
changeset 5 f345bda72bc4
parent 3 46218c8b8afa
child 14 578be2adaf3e
permissions -rw-r--r--
Week 12 contribution of PDK documentation_content. See release notes for details. Fixes Bug 2054, Bug 1583, Bug 381, Bug 390, Bug 463, Bug 1897, Bug 344, Bug 1319, Bug 394, Bug 1520, Bug 1522, Bug 1892"

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-D71D0091-5C4E-5B2F-B1B6-783F11AB5021" xml:lang="en"><title>Writing
to Large Files </title><shortdesc>How to write to large files. </shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<section id="GUID-987FECBF-64DF-4B29-BA60-F69A3CB65CBF"><title>Write() from relative/current position</title><p>There are
four <xref href="GUID-BE0804F6-4375-3C8A-8C83-968F510466E0.dita#GUID-BE0804F6-4375-3C8A-8C83-968F510466E0/GUID-325997F1-3252-358E-B278-44D3A5418FAC"><apiname>RFile::Write()</apiname></xref> overloaded functions relative/current
position that allow you to specify a position greater than 2GB–1 by using
the <xref href="GUID-AAE85115-A8AA-3F6C-BA8C-69F5A23B0D90.dita"><apiname>TInt64</apiname></xref> parameter. </p> <ul>
<li id="GUID-D5A71E59-F7FA-51D3-A85E-35D4E46D1A9F"><p> <xref href="GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7.dita#GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7/GUID-C7A290AB-3EA5-3F0E-A587-31E199F17855"><apiname>RFile64::Write(const
TDesC8&amp; aDes)</apiname></xref>  </p> </li>
<li id="GUID-9A023D6F-98B5-58D9-B0E2-38EAF3FC7AA6"><p> <xref href="GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7.dita#GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7/GUID-A9785313-9473-3CEE-A491-CFFDC3670F4D"><apiname>RFile64::Write(const
TDesC8&amp; aDes, TRequestStatus&amp; aStatus)</apiname></xref>  </p> </li>
<li id="GUID-8FFE6422-3957-57C8-BEAE-450D28FC70F6"><p> <xref href="GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7.dita#GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7/GUID-B8A1627D-48AB-38E4-9CFF-09447E20C6DA"><apiname>RFile64::Write(const
TDesC8&amp; aDes, TInt aLength)</apiname></xref>  </p> </li>
<li id="GUID-0F0AFF90-0635-51C9-9B35-83E87E1A3F0C"><p> <xref href="GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7.dita#GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7/GUID-B0892D23-126A-3A84-B1D3-559572120491"><apiname>RFile64::Write(const
TDesC8&amp; aDes, TInt aLength, TRequestStatus&amp; aStatus)</apiname></xref>. </p> </li>
</ul> <p>The migration procedure is as follows:</p><ol id="GUID-C64C5E8A-A481-5050-A415-ACE8CA0694D0">
<li id="GUID-B61FB842-0C8D-5CB2-9BAC-FE033C216430"><p>Use <xref href="GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7.dita"><apiname>RFile64</apiname></xref> instead
of <xref href="GUID-BE0804F6-4375-3C8A-8C83-968F510466E0.dita"><apiname>RFile</apiname></xref>. </p> <p><codeblock id="GUID-6A0E7FAD-2602-50DB-A200-3A3FB2CE7C56" xml:space="preserve">// RFile file;
RFile64 file;</codeblock> </p> </li>
<li id="GUID-7CC3BEFE-19F7-5FB1-BB99-152A4911BA69"><p>Use <xref href="GUID-AAE85115-A8AA-3F6C-BA8C-69F5A23B0D90.dita"><apiname>TInt64</apiname></xref> variables
in place of the <xref href="GUID-7A2A43EC-6125-3BFE-834B-23C37F7B40D5.dita"><apiname>TInt</apiname></xref> variables representing the number
of bytes written. </p> <p><codeblock id="GUID-34FC7C71-EA56-5779-8E62-0729998AF405" xml:space="preserve">// Tint bytesWritten = 0;
Tint64 bytesWritten = 0;</codeblock> </p> </li>
</ol> <p><b>Example</b> </p><p>The
example below shows an application writing to locations greater than 2GB–1.
The <xref href="GUID-BE0804F6-4375-3C8A-8C83-968F510466E0.dita"><apiname>RFile</apiname></xref> class has been replaced with <xref href="GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7.dita"><apiname>RFile64</apiname></xref> and
the <xref href="GUID-7A2A43EC-6125-3BFE-834B-23C37F7B40D5.dita"><apiname>TInt</apiname></xref> variable that represents the number of bytes written
has been changed to <xref href="GUID-AAE85115-A8AA-3F6C-BA8C-69F5A23B0D90.dita"><apiname>TInt64</apiname></xref>. </p><codeblock id="GUID-2EA7CE6A-C264-54A4-98C8-9AD9C57CBB05" xml:space="preserve">    // 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&lt;1024&gt; 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();
        }</codeblock> </section>
<section id="GUID-E01A0208-911A-4942-B9D1-83722797B376"><title>Write() from absolute position</title><p>There are four <xref href="GUID-BE0804F6-4375-3C8A-8C83-968F510466E0.dita#GUID-BE0804F6-4375-3C8A-8C83-968F510466E0/GUID-325997F1-3252-358E-B278-44D3A5418FAC"><apiname>RFile::Write()</apiname></xref> overloaded
functions that allow you to specify an absolute position greater than 2GB–1
by using the <xref href="GUID-AAE85115-A8AA-3F6C-BA8C-69F5A23B0D90.dita"><apiname>TInt64</apiname></xref> parameter. </p><ul>
<li id="GUID-D9692C56-D4D1-5068-AE4F-0D8209ABE2B5"><p> <xref href="GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7.dita#GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7/GUID-F2DDC64C-2BB3-3944-8377-F2FCAFF2C36B"><apiname>RFile64::Write(TInt64
aPos, const TDesC8&amp; aDes)</apiname></xref>  </p> </li>
<li id="GUID-1C749FBD-5403-59A1-8443-5144B94DBC29"><p> <xref href="GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7.dita#GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7/GUID-52602FFB-4319-3148-A559-C660C59D5409"><apiname>RFile64::Write(TInt64
aPos, const TDesC8&amp; aDes, TRequestStatus&amp; aStatus)</apiname></xref>  </p> </li>
<li id="GUID-8D20B3ED-DE4A-5C77-8453-CDC221CDCBD3"><p> <xref href="GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7.dita#GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7/GUID-9834C13E-50A4-3659-B301-C89C6F71C4CA"><apiname>RFile64::Write(TInt64
aPos, const TDesC8&amp; aDes, TInt aLength)</apiname></xref>  </p> </li>
<li id="GUID-90B8A6B7-15E0-5ADF-98DA-889D2994E9FB"><p> <xref href="GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7.dita#GUID-83A415A0-F417-3CA5-BA10-5AEF119AB1F7/GUID-9A3724AB-9B48-35F4-AE97-CB77AC2D1A1B"><apiname>RFile64::Write(TInt64
aPos, const TDesC8&amp; aDes, TInt aLength, TRequestStatus&amp; aStatus)</apiname></xref>. </p> </li>
</ul><p>The migration procedure is as follows:</p><ol id="GUID-2A682DB4-5D52-5EE1-96CC-AFD56B577E5C">
<li id="GUID-D0169894-B983-5C3A-A0E6-CA76BB48EA7F"><p>Use a <xref href="GUID-AAE85115-A8AA-3F6C-BA8C-69F5A23B0D90.dita"><apiname>TInt64</apiname></xref> instead
of a <xref href="GUID-7A2A43EC-6125-3BFE-834B-23C37F7B40D5.dita"><apiname>TInt</apiname></xref> for the write position. </p> <p><codeblock id="GUID-EE36228D-DDFD-52AD-8BA4-0C8AF38C7DD2" xml:space="preserve">// TInt writePosition = 0;
    TInt64 writePosition = 0;</codeblock> </p> </li>
<li id="GUID-709912EA-32E0-5E7B-A187-7C39AEB13373"><p>Replace <codeph>RFile</codeph> with <codeph>RFile64</codeph>. </p> <p><codeblock id="GUID-EA9C17D0-64D1-571F-BEC2-71574B843148" xml:space="preserve">// RFile file;
    RFile64 file;</codeblock> </p> </li>
</ol><p><b>Example</b> </p><p>To
write to locations beyond 2GB–1 the file must be opened for 64-bit access
and <xref href="GUID-7A2A43EC-6125-3BFE-834B-23C37F7B40D5.dita"><apiname>TInt</apiname></xref> variables should be replaced with <xref href="GUID-AAE85115-A8AA-3F6C-BA8C-69F5A23B0D90.dita"><apiname>TInt64</apiname></xref>. </p><codeblock id="GUID-27FAE59A-F150-54B9-AC95-BA588552E605" xml:space="preserve">    // 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&lt;1024&gt; 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
        }</codeblock> </section>
</conbody></concept>