1 // TarIn.h 2 3 #ifndef ZIP7_INC_ARCHIVE_TAR_IN_H 4 #define ZIP7_INC_ARCHIVE_TAR_IN_H 5 6 #include "../IArchive.h" 7 8 #include "TarItem.h" 9 10 namespace NArchive { 11 namespace NTar { 12 13 enum EErrorType 14 { 15 k_ErrorType_OK, 16 k_ErrorType_Corrupted, 17 k_ErrorType_UnexpectedEnd 18 // , k_ErrorType_Warning 19 }; 20 21 22 struct CTempBuffer 23 { 24 CByteBuffer Buffer; 25 size_t StringSize; // num characters before zero Byte (StringSize <= item.PackSize) 26 bool IsNonZeroTail; 27 bool StringSize_IsConfirmed; 28 CopyToStringCTempBuffer29 void CopyToString(AString &s) 30 { 31 s.Empty(); 32 if (StringSize != 0) 33 s.SetFrom((const char *)(const void *)(const Byte *)Buffer, (unsigned)StringSize); 34 } 35 InitCTempBuffer36 void Init() 37 { 38 StringSize = 0; 39 IsNonZeroTail = false; 40 StringSize_IsConfirmed = false; 41 } 42 }; 43 44 45 class CArchive 46 { 47 public: 48 bool _phySize_Defined; 49 bool _is_Warning; 50 bool PaxGlobal_Defined; 51 bool _is_PaxGlobal_Error; 52 bool _are_Pax_Items; 53 bool _are_Gnu; 54 bool _are_Posix; 55 bool _are_Pax; 56 bool _are_mtime; 57 bool _are_atime; 58 bool _are_ctime; 59 bool _are_pax_path; 60 bool _are_pax_link; 61 bool _are_LongName; 62 bool _are_LongLink; 63 bool _pathPrefix_WasUsed; 64 bool _are_SCHILY_fflags; 65 // bool _isSparse; 66 67 // temp internal vars for ReadItem(): 68 bool filled; 69 private: 70 EErrorType error; 71 72 public: 73 UInt64 _phySize; 74 UInt64 _headersSize; 75 EErrorType _error; 76 77 ISequentialInStream *SeqStream; 78 IInStream *InStream; 79 IArchiveOpenCallback *OpenCallback; 80 UInt64 NumFiles; 81 UInt64 NumFiles_Prev; 82 UInt64 Pos_Prev; 83 // UInt64 NumRecords; 84 // UInt64 NumRecords_Prev; 85 86 CPaxExtra PaxGlobal; 87 Clear()88 void Clear() 89 { 90 SeqStream = NULL; 91 InStream = NULL; 92 OpenCallback = NULL; 93 NumFiles = 0; 94 NumFiles_Prev = 0; 95 Pos_Prev = 0; 96 // NumRecords = 0; 97 // NumRecords_Prev = 0; 98 99 PaxGlobal.Clear(); 100 PaxGlobal_Defined = false; 101 _is_PaxGlobal_Error = false; 102 _are_Pax_Items = false; // if there are final paxItems 103 _are_Gnu = false; 104 _are_Posix = false; 105 _are_Pax = false; 106 _are_mtime = false; 107 _are_atime = false; 108 _are_ctime = false; 109 _are_pax_path = false; 110 _are_pax_link = false; 111 _are_LongName = false; 112 _are_LongLink = false; 113 _pathPrefix_WasUsed = false; 114 _are_SCHILY_fflags = false; 115 // _isSparse = false; 116 117 _is_Warning = false; 118 _error = k_ErrorType_OK; 119 120 _phySize_Defined = false; 121 _phySize = 0; 122 _headersSize = 0; 123 } 124 125 private: 126 CTempBuffer NameBuf; 127 CTempBuffer LinkBuf; 128 CTempBuffer PaxBuf; 129 CTempBuffer PaxBuf_global; 130 131 CByteBuffer Buffer; 132 133 HRESULT ReadDataToBuffer(const CItemEx &item, CTempBuffer &tb, size_t stringLimit); 134 HRESULT Progress(const CItemEx &item, UInt64 posOffset); 135 HRESULT GetNextItemReal(CItemEx &item); 136 HRESULT ReadItem2(CItemEx &itemInfo); 137 public: CArchive()138 CArchive() 139 { 140 // we will call Clear() in CHandler::Close(). 141 // Clear(); // it's not required here 142 } 143 HRESULT ReadItem(CItemEx &itemInfo); 144 }; 145 146 147 API_FUNC_IsArc IsArc_Tar(const Byte *p, size_t size); 148 149 }} 150 151 #endif 152