compressionlibs/ziplib/inc/zipfile.h
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 
       
    17 #ifndef _ZIP_FILE_H_
       
    18 #define _ZIP_FILE_H_
       
    19 
       
    20 #include <e32std.h>
       
    21 #include <s32file.h>
       
    22 #include <charconv.h>
       
    23 
       
    24 #include <localtypes.h>
       
    25 #include <ziparchive.h>
       
    26 #include <zipfilememberinputstream.h>
       
    27 #include <zipfilememberiterator.h>
       
    28 #include <zipfilemember.h>
       
    29 
       
    30 // Forward Class Declaration(s)
       
    31 
       
    32 class CFileInputStream;
       
    33 class CZipFileMemberIterator;
       
    34 class CZipFileMember;
       
    35 namespace ContentAccess
       
    36 	{
       
    37 	class CData;
       
    38 	}
       
    39 
       
    40 // End of Forward Class Declaration(s)
       
    41 
       
    42 
       
    43 /** 
       
    44 A CZipFile represents a ZIP archive contained in a single file. 
       
    45 Multi file zip archives are not supported.
       
    46 
       
    47 @publishedAll
       
    48 @released
       
    49 */
       
    50 class CZipFile : public CZipArchive
       
    51 	{
       
    52 	friend class RZipFileMemberReaderStream;
       
    53 	friend class CZipFileMemberIterator;
       
    54 
       
    55 	public:
       
    56 		/**	ZipFile error enumeration.
       
    57 		*/
       
    58 		enum
       
    59 			{
       
    60 			/** Cannot read file directory in the archive file*/
       
    61 			KZipFileError 		= KZipArchiveMinError - 1,
       
    62 			
       
    63 			/** File not found error. It is not used in current implemenation*/
       
    64 			KZipFileNotFound	= KZipFileError - 1,
       
    65 			
       
    66 			/** File IO error.Any error occurs during a archive file is readed. 
       
    67 			For examples, any error about reading number of disk,
       
    68 			an offset of signature, or the content of file is non-readable.
       
    69 			*/
       
    70 			KZipFileIOError 	= KZipFileError - 2
       
    71 			};
       
    72 
       
    73 	public:
       
    74 		IMPORT_C static CZipFile* NewL(RFs& aFs, RFile& aFile);	
       
    75 		IMPORT_C static CZipFile* NewL(RFs& aFs, const TDesC& aFileName);
       
    76 		IMPORT_C CZipFile(RFs& aFs, const TDesC& aFileName);
       
    77 		IMPORT_C TInt OpenL(void);
       
    78 		IMPORT_C void Close(void);
       
    79 		IMPORT_C virtual ~CZipFile();
       
    80 
       
    81 	protected:
       
    82 		IMPORT_C void ConstructL(const TDesC& aFileName);
       
    83 		
       
    84 		IMPORT_C void ConstructL(RFile& aFile);
       
    85 
       
    86 	public:
       
    87 		IMPORT_C TInt Size(TInt& aSize) const;
       
    88     
       
    89 		IMPORT_C CZipFileMember* MemberL(const TDesC& aName);
       
    90 		IMPORT_C CZipFileMember* CaseInsensitiveMemberL(const TDesC& aName);
       
    91 		IMPORT_C CZipFileMember* CaseSensitiveOrCaseInsensitiveMemberL(const TDesC& aName);
       
    92 		IMPORT_C TInt GetInputStreamL(const CZipFileMember* aMember, RZipFileMemberReaderStream*& aStream);
       
    93 
       
    94   		IMPORT_C CZipFileMemberIterator* GetMembersL(void);
       
    95 	
       
    96     
       
    97 protected:
       
    98 
       
    99 	/** 
       
   100 	Internal representation of a compressed file in a zipfile
       
   101 	@publishedAll
       
   102 	@released
       
   103 	*/
       
   104 	struct TMemberPointer
       
   105 		{
       
   106 		/** the name of a compressed file*/
       
   107 		TFileName*  iName;
       
   108 		
       
   109 		/** Not used in current implementation*/
       
   110 		TUint32		iCentralHeaderOffset;
       
   111 		
       
   112 		/** The local offset of header in a compressed file*/
       
   113 		TUint32	iLocalHeaderOffset;
       
   114 		
       
   115 		/** CRC with 32 bits length in a compressed file*/
       
   116 		TUint32 iCRC32;
       
   117 		
       
   118 		/** The size of compressed file */	
       
   119 		TUint32	iCompressedSize;
       
   120 		
       
   121 		/** The size of file without compressed*/
       
   122 		TUint32	iUncompressedSize;
       
   123 		};
       
   124 		
       
   125 protected:
       
   126 	TInt FindCentralDirectoryTrailer(TUint32& offset);
       
   127     TInt ReadCentralDirectoryTrailer(TUint32 offset, TCentralDirectoryTrailer&);
       
   128     TInt ReadCentralDirectoryHeaderL(TCentralDirectoryHeader&, TMemberPointer&,
       
   129     	CCnvCharacterSetConverter* aConverter, TInt aConverterState);
       
   130 
       
   131 	TInt ReadLocalHeader(TUint32, TLocalHeader&);
       
   132 	
       
   133 	const TMemberPointer* FindMemberPointer(const TDesC&, TBool);
       
   134 	
       
   135     TInt LoadMemberPointersL(void);
       
   136     
       
   137 	RZipFileMemberReaderStream*   MakeInputStreamL(TUint32, TUint32, TUint32, TUint32);
       
   138     CZipFileMember* MakeMemberL(TInt);
       
   139     CZipFileMember* MakeMemberL(const TMemberPointer&, const TLocalHeader&);
       
   140     
       
   141     // File I/O Support
       
   142     void OpenFileL(const TDesC& aFileName);
       
   143   
       
   144     TInt Read(TByte*, TUint32);
       
   145     TInt Read(TUint16&);
       
   146     TInt Read(TUint32&);
       
   147     
       
   148     TInt Seek(TInt);
       
   149 
       
   150 	// Misc
       
   151 	void DeleteMemberPointers(void);
       
   152 
       
   153 private:
       
   154     const TDesC&				iFileName;
       
   155     TUint32 iFileLength;
       
   156 	
       
   157 	/** The central directory of ZIP File Trailer*/
       
   158 	TCentralDirectoryTrailer iTrailer;
       
   159 	
       
   160 	/** The pointer to a a compressed file in a zipfile*/
       
   161 	TMemberPointer*	iMemberPointers;
       
   162 	
       
   163 	RFs& iFs;
       
   164 	
       
   165 	/** The pointer to CData object created from a zip file*/
       
   166 	ContentAccess::CData* iData;
       
   167 	};
       
   168 
       
   169 #endif /* !_ZIP_FILE_H_ */