fill basic ZIP header format
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include "ZipDefine.h"
|
||||
#include "CRC.h"
|
||||
|
||||
#define TARGET_FILE_NAME "MyZip.txt"
|
||||
|
||||
bool ZipArchiver();
|
||||
uint32_t getCRC32(const uint8_t* pData, size_t length);
|
||||
|
||||
@@ -49,11 +51,11 @@ bool ZipArchiver()
|
||||
{
|
||||
LocalFileHeader LFHeader = {};
|
||||
CentralDirectory CentDir = {};
|
||||
EoCDRecord ECDR = {};
|
||||
EoCDRecord EOCDR = {};
|
||||
|
||||
using namespace std;
|
||||
|
||||
ifstream fileIn("MyZip.txt", ios::binary);
|
||||
ifstream fileIn(TARGET_FILE_NAME, ios::binary);
|
||||
bool iRet = fileIn.is_open();
|
||||
if (!iRet)
|
||||
{
|
||||
@@ -75,13 +77,62 @@ bool ZipArchiver()
|
||||
// Read
|
||||
fileIn.read((char *)pFile, fileInSize);
|
||||
|
||||
// Get CRC value
|
||||
// TODO : streamsize 와 size_t 의 mismatch (long long <-> unsigned long long)
|
||||
uint32_t myCRC = getCRC32(pFile, fileInSize);
|
||||
// ZIP 포맷 채워넣기
|
||||
{
|
||||
// Get CRC value
|
||||
// TODO : streamsize 와 size_t 의 mismatch (long long <-> unsigned long long)
|
||||
uint32_t myCRC = getCRC32(pFile, fileInSize);
|
||||
|
||||
// Put CRC value
|
||||
LFHeader.crc32 = myCRC;
|
||||
CentDir.crc32 = myCRC;
|
||||
// Put PK Signature
|
||||
LFHeader.signature = PK_SIGNATURE_LF_HEADER;
|
||||
CentDir.signature = PK_SIGNATURE_CENT_DIR;
|
||||
EOCDR.signature = PK_SIGNATURE_EO_CDR;
|
||||
|
||||
// TOOD : versionMadeBy (Only CentDir)
|
||||
// TODO : versionNeededToExtract
|
||||
// TODO : generalBitFlag
|
||||
|
||||
// Put compressed method (uncompressed)
|
||||
LFHeader.compressionMethod = METHOD_UNCOMPRESSED;
|
||||
CentDir.compressionMethod = METHOD_UNCOMPRESSED;
|
||||
|
||||
// TODO : lastMode[Time|Date]
|
||||
|
||||
// Put CRC value
|
||||
LFHeader.crc32 = myCRC;
|
||||
CentDir.crc32 = myCRC;
|
||||
|
||||
// Put File size
|
||||
LFHeader.sizeOfUncompressed = (uint32_t)fileInSize;
|
||||
CentDir.sizeOfUncompressed = (uint32_t)fileInSize;
|
||||
LFHeader.sizeOfCompressed = LFHeader.sizeOfUncompressed;
|
||||
CentDir.sizeOfCompressed = CentDir.sizeOfUncompressed;
|
||||
|
||||
// Put File name length
|
||||
uint16_t fileNameLeng = strlen(TARGET_FILE_NAME);
|
||||
LFHeader.lengthOfFileName = fileNameLeng;
|
||||
CentDir.lengthOfFileName = fileNameLeng;
|
||||
|
||||
// Extra Field 는 사용하지 않음
|
||||
// LFHeader.lengthOfExtraField = NOT_USED;
|
||||
// CentDir.lengthOfExtraField = NOT_USED;
|
||||
|
||||
// TODO : CentDir 나머지 format
|
||||
// - lengthOfFileComment
|
||||
// - diskNumStart;
|
||||
// - attributeInternal;
|
||||
// - attributeExternal;
|
||||
// - offsetLocalHeader;
|
||||
|
||||
// TODO : EOCDR 나머지 format
|
||||
// - diskNumber
|
||||
// - diskNumber_CentralDirStart
|
||||
// - numOfCentralDir
|
||||
// - numOfEntries;
|
||||
// - SizeOfCentralDir;
|
||||
// - OffsetOfCentralDirOffset;
|
||||
// - LengthOfCommentLength;
|
||||
}
|
||||
|
||||
// Free
|
||||
free(pFile);
|
||||
|
||||
Reference in New Issue
Block a user