本文整理汇总了C++中ZipEntry::setLFHOffset方法的典型用法代码示例。如果您正苦于以下问题:C++ ZipEntry::setLFHOffset方法的具体用法?C++ ZipEntry::setLFHOffset怎么用?C++ ZipEntry::setLFHOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipEntry
的用法示例。
在下文中一共展示了ZipEntry::setLFHOffset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: crunchArchive
/*
* Crunch deleted files out of an archive by shifting the later files down.
*
* Because we're not using a temp file, we do the operation inside the
* current file.
*/
status_t ZipFile::crunchArchive(void)
{
status_t result = NO_ERROR;
int i, count;
long delCount, adjust;
#if 0
printf("CONTENTS:\n");
for (i = 0; i < (int) mEntries.size(); i++) {
printf(" %d: lfhOff=%ld del=%d\n",
i, mEntries[i]->getLFHOffset(), mEntries[i]->getDeleted());
}
printf(" END is %ld\n", (long) mEOCD.mCentralDirOffset);
#endif
/*
* Roll through the set of files, shifting them as appropriate. We
* could probably get a slight performance improvement by sliding
* multiple files down at once (because we could use larger reads
* when operating on batches of small files), but it's not that useful.
*/
count = mEntries.size();
delCount = adjust = 0;
for (i = 0; i < count; i++) {
ZipEntry* pEntry = mEntries[i];
long span;
if (pEntry->getLFHOffset() != 0) {
long nextOffset;
/* Get the length of this entry by finding the offset
* of the next entry. Directory entries don't have
* file offsets, so we need to find the next non-directory
* entry.
*/
nextOffset = 0;
for (int ii = i+1; nextOffset == 0 && ii < count; ii++)
nextOffset = mEntries[ii]->getLFHOffset();
if (nextOffset == 0)
nextOffset = mEOCD.mCentralDirOffset;
span = nextOffset - pEntry->getLFHOffset();
assert(span >= ZipEntry::LocalFileHeader::kLFHLen);
} else {
/* This is a directory entry. It doesn't have
* any actual file contents, so there's no need to
* move anything.
*/
span = 0;
}
//printf("+++ %d: off=%ld span=%ld del=%d [count=%d]\n",
// i, pEntry->getLFHOffset(), span, pEntry->getDeleted(), count);
if (pEntry->getDeleted()) {
adjust += span;
delCount++;
delete pEntry;
mEntries.removeAt(i);
/* adjust loop control */
count--;
i--;
} else if (span != 0 && adjust > 0) {
/* shuffle this entry back */
//printf("+++ Shuffling '%s' back %ld\n",
// pEntry->getFileName(), adjust);
result = filemove(mZipFp, pEntry->getLFHOffset() - adjust,
pEntry->getLFHOffset(), span);
if (result != NO_ERROR) {
/* this is why you use a temp file */
LOGE("error during crunch - archive is toast\n");
return result;
}
pEntry->setLFHOffset(pEntry->getLFHOffset() - adjust);
}
}
/*
* Fix EOCD info. We have to wait until the end to do some of this
* because we use mCentralDirOffset to determine "span" for the
* last entry.
*/
mEOCD.mCentralDirOffset -= adjust;
mEOCD.mNumEntries -= delCount;
mEOCD.mTotalNumEntries -= delCount;
mEOCD.mCentralDirSize = 0; // mark invalid; set by flush()
assert(mEOCD.mNumEntries == mEOCD.mTotalNumEntries);
assert(mEOCD.mNumEntries == count);
return result;
//.........这里部分代码省略.........
示例2: 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;
}
示例3: add
/*
* Add an entry by copying it from another zip file. If "padding" is
* nonzero, the specified number of bytes will be added to the "extra"
* field in the header.
*
* If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
*/
status_t ZipFile::add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
int padding, ZipEntry** ppEntry)
{
ZipEntry* pEntry = NULL;
status_t result;
long lfhPosn, endPosn;
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(pSourceZip, pSourceEntry);
if (result != NO_ERROR)
goto bail;
if (padding != 0) {
result = pEntry->addPadding(padding);
if (result != NO_ERROR)
goto bail;
}
/*
* From here on out, failures are more interesting.
*/
mNeedCDRewrite = true;
/*
* Write the LFH. Since we're not recompressing the data, we already
* have all of the fields filled out.
*/
lfhPosn = ftell(mZipFp);
pEntry->mLFH.write(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;
}
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)
{
LOGW("copy of '%s' failed\n", pEntry->mCDE.mFileName);
result = UNKNOWN_ERROR;
goto bail;
}
/*
* Update file offsets.
*/
endPosn = ftell(mZipFp);
/*
* Success! Fill out new values.
*/
pEntry->setLFHOffset(lfhPosn); // sets mCDE.mLocalHeaderRelOffset
mEOCD.mNumEntries++;
mEOCD.mTotalNumEntries++;
mEOCD.mCentralDirSize = 0; // mark invalid; set by flush()
mEOCD.mCentralDirOffset = endPosn;
/*
* Add pEntry to the list.
*/
mEntries.add(pEntry);
if (ppEntry != NULL)
*ppEntry = pEntry;
pEntry = NULL;
//.........这里部分代码省略.........
示例4: addRecompress
//.........这里部分代码省略.........
/*
* 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.
*/
endPosn = ftell(mZipFp);
/*
* Success! Fill out new values.
*/
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;
result = NO_ERROR;
bail:
delete pEntry;
return result;
}