compressionlibs/ziplib/src/ezlib/filebuffer.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <ezfilebuffer.h>
       
    17 #include <ezstream.h>
       
    18 
       
    19 _LIT(KFileBuffer,"FileBuffer");
       
    20 
       
    21 void CEZFileBufferManager::ConstructL(TInt aBufferSize)
       
    22 	{
       
    23 	__ASSERT_ALWAYS(aBufferSize > 0, User::Panic(KFileBuffer, EBadInitialization));
       
    24 
       
    25 	iBufferSize = aBufferSize;
       
    26 
       
    27 	iInputBuffer = new (ELeave) TUint8[iBufferSize];
       
    28 	iOutputBuffer = new (ELeave) TUint8[iBufferSize];
       
    29 
       
    30 	iInputDescriptor.Set(iInputBuffer,0,iBufferSize);
       
    31 	iOutputDescriptor.Set(iOutputBuffer,0,iBufferSize);
       
    32 	}
       
    33 
       
    34 CEZFileBufferManager::~CEZFileBufferManager()
       
    35 	{
       
    36 	delete[] iInputBuffer;
       
    37 	delete[] iOutputBuffer;
       
    38 	}
       
    39 
       
    40 CEZFileBufferManager::CEZFileBufferManager(RFile &aInput, RFile &aOutput) : 
       
    41 	iInputFile(aInput), iOutputFile(aOutput), iInputDescriptor(NULL,0), iOutputDescriptor(NULL,0)
       
    42 	{
       
    43 
       
    44 	}
       
    45 
       
    46 /**
       
    47 Creates a new CEZFileBufferManager object and leave it on the CleanupStack
       
    48 
       
    49 @param aInput the input file
       
    50 @param aOutput the output file
       
    51 @param aBufferSize the required size of the buffers
       
    52 @return the new CEZFileBufferManager object, on the CleanupStack
       
    53 */
       
    54 EXPORT_C CEZFileBufferManager* CEZFileBufferManager::NewLC(RFile &aInput, RFile &aOutput, TInt aBufferSize)
       
    55 	{
       
    56 	CEZFileBufferManager *fb = new (ELeave) CEZFileBufferManager(aInput,aOutput);
       
    57 	CleanupStack::PushL(fb);
       
    58 	fb->ConstructL(aBufferSize);
       
    59 	return fb;
       
    60 	}
       
    61 
       
    62 /**
       
    63 Creates a new CEZFileBufferManager object
       
    64 
       
    65 @param aInput the input file
       
    66 @param aOutput the output file
       
    67 @param aBufferSize the required size of the buffers
       
    68 @return the new CEZFileBufferManager object
       
    69 */
       
    70 EXPORT_C CEZFileBufferManager* CEZFileBufferManager::NewL(RFile &aInput, RFile &aOutput, TInt aBufferSize)
       
    71 	{
       
    72 	CEZFileBufferManager *fb = new (ELeave) CEZFileBufferManager(aInput,aOutput);
       
    73 	CleanupStack::PushL(fb);
       
    74 	fb->ConstructL(aBufferSize);
       
    75 	CleanupStack::Pop();
       
    76 	return fb;
       
    77 	}
       
    78 
       
    79 
       
    80 void CEZFileBufferManager::InitializeL(CEZZStream &aZStream)
       
    81 	{
       
    82 	User::LeaveIfError(iInputFile.Read(iInputDescriptor));
       
    83 	aZStream.SetInput(iInputDescriptor);
       
    84 	aZStream.SetOutput(iOutputDescriptor);
       
    85 	}
       
    86 
       
    87 void CEZFileBufferManager::NeedInputL(CEZZStream &aZStream)
       
    88 	{
       
    89 	User::LeaveIfError(iInputFile.Read(iInputDescriptor));
       
    90 	aZStream.SetInput(iInputDescriptor);
       
    91 	}
       
    92 
       
    93 void CEZFileBufferManager::NeedOutputL(CEZZStream &aZStream)
       
    94 	{
       
    95 	TPtrC8 od = aZStream.OutputDescriptor();
       
    96 	User::LeaveIfError(iOutputFile.Write(od));
       
    97 	aZStream.SetOutput(iOutputDescriptor);
       
    98 	}
       
    99 
       
   100 void CEZFileBufferManager::FinalizeL(CEZZStream &aZStream)
       
   101 	{
       
   102 	TPtrC8 od = aZStream.OutputDescriptor();
       
   103 	User::LeaveIfError(iOutputFile.Write(od));
       
   104 	}