MCPcopy Create free account
hub / github.com/9miao/CrossApp / getFileDataFromZip

Method getFileDataFromZip

CrossApp/platform/CCFileUtils.cpp:77–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize)
78{
79 unsigned char * pBuffer = NULL;
80 unzFile pFile = NULL;
81 *pSize = 0;
82
83 do
84 {
85 CC_BREAK_IF(!pszZipFilePath || !pszFileName);
86 CC_BREAK_IF(strlen(pszZipFilePath) == 0);
87
88 pFile = unzOpen(pszZipFilePath);
89 CC_BREAK_IF(!pFile);
90
91 int nRet = unzLocateFile(pFile, pszFileName, 1);
92 CC_BREAK_IF(UNZ_OK != nRet);
93
94 char szFilePathA[260];
95 unz_file_info FileInfo;
96 nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0);
97 CC_BREAK_IF(UNZ_OK != nRet);
98
99 nRet = unzOpenCurrentFile(pFile);
100 CC_BREAK_IF(UNZ_OK != nRet);
101
102 pBuffer = new unsigned char[FileInfo.uncompressed_size];
103 int CC_UNUSED nSize = unzReadCurrentFile(pFile, pBuffer, FileInfo.uncompressed_size);
104 CCAssert(nSize == 0 || nSize == (int)FileInfo.uncompressed_size, "the file size is wrong");
105
106 *pSize = FileInfo.uncompressed_size;
107 unzCloseCurrentFile(pFile);
108 } while (0);
109
110 if (pFile)
111 {
112 unzClose(pFile);
113 }
114
115 return pBuffer;
116}
117
118std::string CCFileUtils::getFileString(const char* pszFilePath)
119{

Callers

nothing calls this directly

Calls 7

unzOpenFunction · 0.85
unzLocateFileFunction · 0.85
unzGetCurrentFileInfoFunction · 0.85
unzOpenCurrentFileFunction · 0.85
unzReadCurrentFileFunction · 0.85
unzCloseCurrentFileFunction · 0.85
unzCloseFunction · 0.85

Tested by

no test coverage detected