00001 #ifndef CLASSLIB_ZIP_INPUT_STREAM_H 00002 # define CLASSLIB_ZIP_INPUT_STREAM_H 00003 00004 //<<<<<< INCLUDES >>>>>> 00005 00006 # include "classlib/zip/ZInputStream.h" 00007 # include "classlib/zip/ZConstants.h" 00008 # include <vector> 00009 # include <string> 00010 00011 namespace lat { 00012 //<<<<<< PUBLIC DEFINES >>>>>> 00013 //<<<<<< PUBLIC CONSTANTS >>>>>> 00014 //<<<<<< PUBLIC TYPES >>>>>> 00015 00016 class ZipMember; 00017 00018 //<<<<<< PUBLIC VARIABLES >>>>>> 00019 //<<<<<< PUBLIC FUNCTIONS >>>>>> 00020 //<<<<<< CLASS DECLARATIONS >>>>>> 00021 00022 // Reads a zip archive straight off an input stream; central directory 00023 // features are not available in the produced members (file comment, 00024 // global external data) until the whole archive has been read (at 00025 // which points the already seen members will be filled in with the 00026 // global data). 00027 // 00028 // Handle stored and compressed files! 00029 class ZipInputStream : public ZInputStream, public ZConstants 00030 { 00031 public: 00032 ZipInputStream (InputStream *input); 00033 ~ZipInputStream (void); 00034 00035 using ZInputStream::read; 00036 00037 virtual ZipMember * nextMember (void); 00038 virtual IOSize available (void); 00039 virtual IOSize read (void *into, IOSize n); 00040 virtual IOSize skip (IOSize n); 00041 virtual void closeMember (void); 00042 00043 virtual void close (void); 00044 00045 virtual void reset (void); 00046 00047 virtual ZipMember * sync (void); 00048 00049 protected: 00050 virtual IOSize fill (void *buffer, IOSize length); 00051 00052 private: 00053 void resetState (bool destroy); 00054 unsigned readHeader (void); 00055 unsigned findHeader (void); 00056 ZipMember * readMemberHeader (unsigned char *buf, IOSize length); 00057 void readDirectory (unsigned char *buf, IOSize length); 00058 void readEndHeader (unsigned char *buf, IOSize length); 00059 00060 typedef std::vector<ZipMember *> MemberList; 00061 MemberList m_members; //< Members read and to be updated 00062 ZipMember *m_current; //< The member that is being read 00063 IOOffset m_compressed; //< Compressed data left to read 00064 IOOffset m_uncompressed; //< Uncompressed data left to read 00065 unsigned m_magic; //< Header magic for current state 00066 std::string m_comment; //< Archive comment 00067 IOOffset m_total; //< Total bytes read so far 00068 IOOffset m_directory; //< Position of directory from start 00069 bool m_dummy; //< Indicates when dummy end byte read 00070 }; 00071 00072 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> 00073 //<<<<<< INLINE MEMBER FUNCTIONS >>>>>> 00074 00075 } // namespace lat 00076 #endif // CLASSLIB_ZIP_INPUT_STREAM_H