本文整理汇总了C++中ZipEntry::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ ZipEntry::getSize方法的具体用法?C++ ZipEntry::getSize怎么用?C++ ZipEntry::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipEntry
的用法示例。
在下文中一共展示了ZipEntry::getSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readEntry
int ZipArchive::readEntry(const ZipEntry& zipEntry, std::ofstream& ofOutput, State state, libzippp_uint64 chunksize) const {
if (!ofOutput.is_open()) { return LIBZIPPP_ERROR_INVALID_PARAMETER; }
if (!isOpen()) { return LIBZIPPP_ERROR_NOT_OPEN; }
if (zipEntry.zipFile!=this) { return LIBZIPPP_ERROR_INVALID_ENTRY; }
int iRes = LIBZIPPP_OK;
int flag = state==ORIGINAL ? ZIP_FL_UNCHANGED : 0;
struct zip_file* zipFile = zip_fopen_index(zipHandle, zipEntry.getIndex(), flag);
if (zipFile) {
libzippp_uint64 maxSize = zipEntry.getSize();
if (!chunksize) { chunksize = DEFAULT_CHUNK_SIZE; } // use the default chunk size (512K) if not specified by the user
if (maxSize<chunksize) {
char* data = new char[maxSize];
if (data!=NULL) {
libzippp_int64 result = zip_fread(zipFile, data, maxSize);
if (result>0) {
if (result != static_cast<libzippp_int64>(maxSize)) {
iRes = LIBZIPPP_ERROR_OWRITE_INDEX_FAILURE;
} else {
ofOutput.write(data, maxSize);
if (!ofOutput) { iRes = LIBZIPPP_ERROR_OWRITE_FAILURE; }
}
} else {
iRes = LIBZIPPP_ERROR_FREAD_FAILURE;
}
delete[] data;
} else {
iRes = LIBZIPPP_ERROR_MEMORY_ALLOCATION;
}
} else {
libzippp_uint64 uWrittenBytes = 0;
libzippp_int64 result = 0;
char* data = new char[chunksize];
if (data!=NULL) {
int nbChunks = maxSize/chunksize;
for (int uiChunk=0 ; uiChunk<nbChunks ; ++uiChunk) {
result = zip_fread(zipFile, data, chunksize);
if (result>0) {
if (result!=static_cast<libzippp_int64>(chunksize)) {
iRes = LIBZIPPP_ERROR_OWRITE_INDEX_FAILURE;
break;
} else {
ofOutput.write(data, chunksize);
if (!ofOutput) {
iRes = LIBZIPPP_ERROR_OWRITE_FAILURE;
break;
}
uWrittenBytes += result;
}
} else {
iRes = LIBZIPPP_ERROR_FREAD_FAILURE;
break;
}
}
delete[] data;
} else {
iRes = LIBZIPPP_ERROR_MEMORY_ALLOCATION;
}
int leftOver = maxSize%chunksize;
if (iRes==0 && leftOver>0) {
char* data = new char[leftOver];
if (data!=NULL) {
result = zip_fread(zipFile, data, leftOver);
if (result>0) {
if (result!=static_cast<libzippp_int64>(leftOver)) {
iRes = LIBZIPPP_ERROR_OWRITE_INDEX_FAILURE;
} else {
ofOutput.write(data, leftOver);
if (!ofOutput) {
iRes = LIBZIPPP_ERROR_OWRITE_FAILURE;
} else {
uWrittenBytes += result;
if (uWrittenBytes!=maxSize) {
iRes = LIBZIPPP_ERROR_UNKNOWN; // shouldn't occur but let's be careful
}
}
}
} else {
iRes = LIBZIPPP_ERROR_FREAD_FAILURE;
}
} else {
iRes = LIBZIPPP_ERROR_MEMORY_ALLOCATION;
}
delete[] data;
}
}
zip_fclose(zipFile);
} else {
iRes = LIBZIPPP_ERROR_FOPEN_FAILURE;
}
return iRes;
}