sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\misc\unzip.cpp sl@0: // sl@0: // sl@0: sl@0: #include "unzip.h" sl@0: #include "inflate.h" sl@0: sl@0: //#include sl@0: //GLREF_C RTest test; sl@0: sl@0: const TInt INBUFSIZE=0x2000; sl@0: sl@0: TZipInfo* TheZipInfo; sl@0: sl@0: #define Z (*TheZipInfo) sl@0: sl@0: extern "C" { sl@0: sl@0: extern int inflate(); sl@0: sl@0: TUint8 inbuf[INBUFSIZE]; sl@0: TUint8* volatile inptr; /* index of next byte to be processed in inbuf */ sl@0: TUint8* volatile inbuf_end; /* pointer to last valid input byte + 1 */ sl@0: TUint8* volatile outptr; /* pointer to output data */ sl@0: sl@0: TAny* malloc(TUint aSize) sl@0: { sl@0: return MALLOC((TInt)aSize); sl@0: } sl@0: sl@0: void free(TAny* aPtr) sl@0: { sl@0: FREE(aPtr); sl@0: } sl@0: sl@0: TUint8 fill_inbuf() sl@0: { sl@0: WAIT_FOR_ANY_REQUEST(); // wait for a block from the file sl@0: TUint w=Z.iFileBufW; sl@0: TInt avail=(TInt)w-(TInt)Z.iFileBufR; sl@0: TInt amount=(avail>(TInt)INBUFSIZE)?INBUFSIZE:avail; sl@0: TInt rix=(TInt)(Z.iFileBufR & (Z.iFileBufSize-1)); sl@0: memcpy(inbuf,Z.iFileBuf+rix,amount); sl@0: Z.iFileBufR+=amount; sl@0: inptr=inbuf; sl@0: inbuf_end=inbuf+amount; sl@0: return *inptr++; sl@0: } sl@0: sl@0: void process_block(int error) sl@0: { sl@0: AcceptUnzippedBlock(Z, (TUint8*&)outptr, error); sl@0: } sl@0: } sl@0: sl@0: TInt ParseZipHeader(TZipInfo& a) sl@0: { sl@0: TInt avail=inbuf_end-inptr; sl@0: if (avail=(TInt)INBUFSIZE); sl@0: TInt req_len=Min(a.iRemain,INBUFSIZE); sl@0: TInt len=req_len; sl@0: TInt wix=(TInt)(a.iFileBufW & (a.iFileBufSize-1)); sl@0: TInt r=ReadInputData(a.iFileBuf+wix,len); sl@0: if (len>req_len) sl@0: len=req_len; sl@0: if (r==KErrNone) sl@0: { sl@0: a.iFileBufW+=len; sl@0: a.iRemain-=len; sl@0: } sl@0: return r; sl@0: } sl@0: