本文整理汇总了C++中ZipEntry::setDataInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ ZipEntry::setDataInfo方法的具体用法?C++ ZipEntry::setDataInfo怎么用?C++ ZipEntry::setDataInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipEntry
的用法示例。
在下文中一共展示了ZipEntry::setDataInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addCommon
//.........这里部分代码省略.........
src, dst);
failed = true;
}
}
if (failed) {
compressionMethod = ZipEntry::kCompressStored;
if (inputFp) rewind(inputFp);
fseek(mZipFp, startPosn, SEEK_SET);
/* fall through to kCompressStored case */
}
}
/* handle "no compression" request, or failed compression from above */
if (compressionMethod == ZipEntry::kCompressStored) {
if (inputFp) {
result = copyFpToFp(mZipFp, inputFp, &crc);
} else {
result = copyDataToFp(mZipFp, data, size, &crc);
}
if (result != NO_ERROR) {
// don't need to truncate; happens in CDE rewrite
LOGD("failed copying data in\n");
goto bail;
}
}
// currently seeked to end of file
uncompressedLen = inputFp ? ftell(inputFp) : size;
} else if (sourceType == ZipEntry::kCompressDeflated) {
/* we should support uncompressed-from-compressed, but it's not
* important right now */
assert(compressionMethod == ZipEntry::kCompressDeflated);
bool scanResult;
int method;
long compressedLen;
scanResult = ZipUtils::examineGzip(inputFp, &method, &uncompressedLen,
&compressedLen, &crc);
if (!scanResult || method != ZipEntry::kCompressDeflated) {
LOGD("this isn't a deflated gzip file?");
result = UNKNOWN_ERROR;
goto bail;
}
result = copyPartialFpToFp(mZipFp, inputFp, compressedLen, NULL);
if (result != NO_ERROR) {
LOGD("failed copying gzip data in\n");
goto bail;
}
} else {
assert(false);
result = UNKNOWN_ERROR;
goto bail;
}
/*
* We could write the "Data Descriptor", but there doesn't seem to
* be any point since we're going to go back and write the LFH.
*
* Update file offsets.
*/
endPosn = ftell(mZipFp); // seeked to end of compressed data
/*
* Success! Fill out new values.
*/
pEntry->setDataInfo(uncompressedLen, endPosn - startPosn, crc,
compressionMethod);
modWhen = getModTime(inputFp ? fileno(inputFp) : fileno(mZipFp));
pEntry->setModWhen(modWhen);
pEntry->setLFHOffset(lfhPosn);
mEOCD.mNumEntries++;
mEOCD.mTotalNumEntries++;
mEOCD.mCentralDirSize = 0; // mark invalid; set by flush()
mEOCD.mCentralDirOffset = endPosn;
/*
* Go back and write the LFH.
*/
if (fseek(mZipFp, lfhPosn, SEEK_SET) != 0) {
result = UNKNOWN_ERROR;
goto bail;
}
pEntry->mLFH.write(mZipFp);
/*
* Add pEntry to the list.
*/
mEntries.add(pEntry);
if (ppEntry != NULL)
*ppEntry = pEntry;
pEntry = NULL;
bail:
if (inputFp != NULL)
fclose(inputFp);
delete pEntry;
return result;
}
示例2: addRecompress
/*
* Add an entry by copying it from another zip file, recompressing with
* Zopfli if already compressed.
*
* If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
*/
status_t ZipFile::addRecompress(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
ZipEntry** ppEntry)
{
ZipEntry* pEntry = NULL;
status_t result;
long lfhPosn, startPosn, endPosn, uncompressedLen;
if (mReadOnly)
return INVALID_OPERATION;
/* make sure we're in a reasonable state */
assert(mZipFp != NULL);
assert(mEntries.size() == mEOCD.mTotalNumEntries);
if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
result = UNKNOWN_ERROR;
goto bail;
}
pEntry = new ZipEntry;
if (pEntry == NULL) {
result = NO_MEMORY;
goto bail;
}
result = pEntry->initFromExternal(pSourceEntry);
if (result != NO_ERROR)
goto bail;
/*
* From here on out, failures are more interesting.
*/
mNeedCDRewrite = true;
/*
* Write the LFH, even though it's still mostly blank. We need it
* as a place-holder. In theory the LFH isn't necessary, but in
* practice some utilities demand it.
*/
lfhPosn = ftell(mZipFp);
pEntry->mLFH.write(mZipFp);
startPosn = ftell(mZipFp);
/*
* Copy the data over.
*
* If the "has data descriptor" flag is set, we want to copy the DD
* fields as well. This is a fixed-size area immediately following
* the data.
*/
if (fseek(pSourceZip->mZipFp, pSourceEntry->getFileOffset(), SEEK_SET) != 0)
{
result = UNKNOWN_ERROR;
goto bail;
}
uncompressedLen = pSourceEntry->getUncompressedLen();
if (pSourceEntry->isCompressed()) {
void *buf = pSourceZip->uncompress(pSourceEntry);
if (buf == NULL) {
result = NO_MEMORY;
goto bail;
}
long startPosn = ftell(mZipFp);
uint32_t crc;
if (compressFpToFp(mZipFp, NULL, buf, uncompressedLen, &crc) != NO_ERROR) {
ALOGW("recompress of '%s' failed\n", pEntry->mCDE.mFileName);
result = UNKNOWN_ERROR;
free(buf);
goto bail;
}
long endPosn = ftell(mZipFp);
pEntry->setDataInfo(uncompressedLen, endPosn - startPosn,
pSourceEntry->getCRC32(), ZipEntry::kCompressDeflated);
free(buf);
} else {
off_t copyLen;
copyLen = pSourceEntry->getCompressedLen();
if ((pSourceEntry->mLFH.mGPBitFlag & ZipEntry::kUsesDataDescr) != 0)
copyLen += ZipEntry::kDataDescriptorLen;
if (copyPartialFpToFp(mZipFp, pSourceZip->mZipFp, copyLen, NULL)
!= NO_ERROR)
{
ALOGW("copy of '%s' failed\n", pEntry->mCDE.mFileName);
result = UNKNOWN_ERROR;
goto bail;
}
}
/*
* Update file offsets.
*/
//.........这里部分代码省略.........