static jlong StrictJarFile_nativeStartIteration(JNIEnv* env, jobject, jlong nativeHandle, jstring prefix) { ScopedUtfChars prefixChars(env, prefix); if (prefixChars.c_str() == NULL) { return static_cast<jlong>(-1); } IterationHandle* handle = new IterationHandle(); int32_t error = 0; if (prefixChars.size() == 0) { error = StartIteration(reinterpret_cast<ZipArchiveHandle>(nativeHandle), handle->CookieAddress(), NULL, NULL); } else { ZipString entry_name(prefixChars.c_str()); error = StartIteration(reinterpret_cast<ZipArchiveHandle>(nativeHandle), handle->CookieAddress(), &entry_name, NULL); } if (error) { throwIoException(env, error); return static_cast<jlong>(-1); } return reinterpret_cast<jlong>(handle); }
void CFiles::GetFileNames(CMapStringInt* pcFileNames) { CFileIterator cIter; CFileIteratorReturn* pcReturn; int* piValue; int iRank; pcReturn = StartIteration(&cIter); while (pcReturn) { piValue = pcFileNames->Get(pcReturn->GetFullName()); if (!piValue) { iRank = pcReturn->GetFileRank() << 16; pcFileNames->Put(pcReturn->GetFullName(), iRank + 1); } else { iRank = (*piValue) >> 16; if (iRank < pcReturn->GetFileRank()) { iRank = pcReturn->GetFileRank() << 16; *piValue = iRank | (*piValue & 0xFFFF); } (*piValue)++; } pcReturn = Iterate(&cIter); } StopIteration(&cIter); }
void CPackFiles::GetFiles(CArrayPackFileNodePtrs* pcPackFiles) { CPackFileIterator cIter; CFileNodePackFileNode* pcFile; pcFile = StartIteration(&cIter); while (pcFile) { pcPackFiles->Add(&pcFile); pcFile = Iterate(&cIter); } StopIteration(&cIter); }
static void Iterate_all_files(benchmark::State& state) { std::unique_ptr<TemporaryFile> temp_file(CreateZip()); ZipArchiveHandle handle; void* iteration_cookie; ZipEntry data; ZipString name; while (state.KeepRunning()) { OpenArchive(temp_file->path, &handle); StartIteration(handle, &iteration_cookie); while (Next(iteration_cookie, &data, &name) == 0) { } EndIteration(iteration_cookie); CloseArchive(handle); } }
std::unique_ptr<ZipFileCollection> ZipFileCollection::create(const StringPiece& path, std::string* outError) { constexpr static const int32_t kEmptyArchive = -6; std::unique_ptr<ZipFileCollection> collection = std::unique_ptr<ZipFileCollection>( new ZipFileCollection()); int32_t result = OpenArchive(path.data(), &collection->mHandle); if (result != 0) { // If a zip is empty, result will be an error code. This is fine and we should // return an empty ZipFileCollection. if (result == kEmptyArchive) { return collection; } if (outError) *outError = ErrorCodeString(result); return {}; } void* cookie = nullptr; result = StartIteration(collection->mHandle, &cookie, nullptr, nullptr); if (result != 0) { if (outError) *outError = ErrorCodeString(result); return {}; } using IterationEnder = std::unique_ptr<void, decltype(EndIteration)*>; IterationEnder iterationEnder(cookie, EndIteration); ZipString zipEntryName; ZipEntry zipData; while ((result = Next(cookie, &zipData, &zipEntryName)) == 0) { std::string zipEntryPath = std::string(reinterpret_cast<const char*>(zipEntryName.name), zipEntryName.name_length); std::string nestedPath = path.toString() + "@" + zipEntryPath; collection->mFiles[zipEntryPath] = util::make_unique<ZipFile>(collection->mHandle, zipData, Source(nestedPath)); } if (result != -1) { if (outError) *outError = ErrorCodeString(result); return {}; } return collection; }
static void ProcessAll(ZipArchiveHandle zah) { MaybeShowHeader(); // libziparchive iteration order doesn't match the central directory. // We could sort, but that would cost extra and wouldn't match either. void* cookie; int err = StartIteration(zah, &cookie); if (err != 0) { error(1, 0, "couldn't iterate %s: %s", archive_name, ErrorCodeString(err)); } ZipEntry entry; ZipString string; while ((err = Next(cookie, &entry, &string)) >= 0) { std::string name(string.name, string.name + string.name_length); if (ShouldInclude(name)) ProcessOne(zah, entry, name); } if (err < -1) error(1, 0, "failed iterating %s: %s", archive_name, ErrorCodeString(err)); EndIteration(cookie); MaybeShowFooter(); }