Update contrib.
1 // Copyright (c) 1998-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\misc\unzip.cpp
21 //#include <e32test.h>
24 const TInt INBUFSIZE=0x2000;
28 #define Z (*TheZipInfo)
34 TUint8 inbuf[INBUFSIZE];
35 TUint8* volatile inptr; /* index of next byte to be processed in inbuf */
36 TUint8* volatile inbuf_end; /* pointer to last valid input byte + 1 */
37 TUint8* volatile outptr; /* pointer to output data */
39 TAny* malloc(TUint aSize)
41 return MALLOC((TInt)aSize);
51 WAIT_FOR_ANY_REQUEST(); // wait for a block from the file
53 TInt avail=(TInt)w-(TInt)Z.iFileBufR;
54 TInt amount=(avail>(TInt)INBUFSIZE)?INBUFSIZE:avail;
55 TInt rix=(TInt)(Z.iFileBufR & (Z.iFileBufSize-1));
56 memcpy(inbuf,Z.iFileBuf+rix,amount);
59 inbuf_end=inbuf+amount;
63 void process_block(int error)
65 AcceptUnzippedBlock(Z, (TUint8*&)outptr, error);
69 TInt ParseZipHeader(TZipInfo& a)
71 TInt avail=inbuf_end-inptr;
72 if (avail<KZipLocalHeaderLen)
74 TUint sig=*(TUint*)inptr; // OK since at beginning of buffer
76 if (sig!=KZipSignature)
82 memcpy(&a.iCrc,inptr,12); // crc, comp size, uncomp size
84 a.iFileNameLength=*inptr | (inptr[1]<<8);
86 a.iExtraLength=*inptr | (inptr[1]<<8);
88 if (a.iFlags & (CRPFLG|EXTFLG))
89 return KErrNotSupported;
90 if (a.iMethod!=STORED && a.iMethod!=DEFLATED)
91 return KErrNotSupported;
92 if (avail<KZipLocalHeaderLen+a.iFileNameLength+a.iExtraLength)
95 a.iDataOffset=30+a.iFileNameLength+a.iExtraLength;
96 TInt fnamelen=Min(a.iFileNameLength,a.iName.MaxLength());
97 TPtrC8 fileNamePtr(inptr,fnamelen);
98 a.iName.Copy(fileNamePtr);
102 TInt UnzipThread(TAny* aInfo)
104 TheZipInfo=(TZipInfo*)aInfo;
105 Z.iProcessedHeader=KRequestPending;
110 TInt r=ParseZipHeader(Z);
113 inptr=inbuf+Z.iDataOffset;
115 WAIT_FOR_REQUEST(Z.iProcessedHeader);
118 r=UnzipComplete(Z, outptr, r);
122 TInt InitInfo(TZipInfo& a)
124 a.iInBufSize=INBUFSIZE;
128 a.iProcessedHeader=KRequestPending;
132 a.iThreadStatus=KRequestPending;
136 TInt ReadBlockToBuffer(TZipInfo& a)
139 for (n=0; n<10 && a.iFileBufW-a.iFileBufR==a.iFileBufSize; ++n)
141 // test.Printf(_L("FULL!"));
142 DELAY(20000); // buffer full so wait a bit
144 if (a.iFileBufW-a.iFileBufR==a.iFileBufSize)
146 // TInt avail=(TInt)a.iFileBufSize+(TInt)a.iFileBufR-(TInt)a.iFileBufW;
147 // test(avail>=(TInt)INBUFSIZE);
148 TInt req_len=Min(a.iRemain,INBUFSIZE);
150 TInt wix=(TInt)(a.iFileBufW & (a.iFileBufSize-1));
151 TInt r=ReadInputData(a.iFileBuf+wix,len);