My main problem is that when reading any .zip file, it isn't reading the data into the struct properly and so the filenameLength property is set to 0 even though it should be correct. I tested with zip.seekg(26) and read that value which gave me the correct value, which makes me think something is wrong with my struct. So I printed out the size of my struct and it gave off 32 even though all the property sizes added up equals 30. What am I doing wrong?
struct ZIPHeader
{
int sig; // 4
short versionMadeBy; // 6
short extractorversion; // 8
short genflag; // 10
short lastModificationTime; // 12
short lastModificationDate; // 14
int crc; // 18
int compressedSize; // 22
int uncompressedSize; // 26
short filenameLength; // 28
short extraFieldLength; // 30
} zheader;
void PrintZipInfo(const char* dir)
{
cout << "Sizeofheader: " << sizeof(ZIPHeader) << endl;
ifstream zip(dir, ios::binary);
zip.read((char *)&zheader, sizeof(ZIPHeader));
cout << "File name length: " << zheader.filenameLength << endl;
}
Outputs
Sizeofheader: 32
File name length: 0