nglIStream* nglZipFS::OpenRead(const nglPath& rPath) { nglString p(rPath.GetVolumeLessPath()); p.TrimLeft(_T('/')); //wprintf(_T("trimed path '%s'\n"), p.GetChars()); nglPath path(p); Node* pNode = mRoot.Find(path); if (!pNode) return NULL; if (!pNode->mIsLeaf) return NULL; unz_file_pos file_pos; file_pos.num_of_file = pNode->mNumOfFile; file_pos.pos_in_zip_directory = pNode->mPosInZipDirectory; if (unzGoToFilePos(mpPrivate->mZip, &file_pos) != UNZ_OK) return NULL; if (unzOpenCurrentFile(mpPrivate->mZip) != UNZ_OK) return NULL; void* pUnzip = unzGetCurrentFile(mpPrivate->mZip); if (!pUnzip) return NULL; return new nglIZip(this, pUnzip, pNode->mSize, pNode->mNumOfFile, pNode->mPosInZipDirectory); }
unzFile ZipArchive::get_file_handle(String p_file) const { ERR_FAIL_COND_V(!file_exists(p_file), NULL); File file = files[p_file]; FileAccess *f = FileAccess::open(packages[file.package].filename, FileAccess::READ); ERR_FAIL_COND_V(!f, NULL); zlib_filefunc_def io; zeromem(&io, sizeof(io)); io.opaque = f; io.zopen_file = godot_open; io.zread_file = godot_read; io.zwrite_file = godot_write; io.ztell_file = godot_tell; io.zseek_file = godot_seek; io.zclose_file = godot_close; io.zerror_file = godot_testerror; io.alloc_mem = godot_alloc; io.free_mem = godot_free; unzFile pkg = unzOpen2(packages[file.package].filename.utf8().get_data(), &io); ERR_FAIL_COND_V(!pkg, NULL); int unz_err = unzGoToFilePos(pkg, &file.file_pos); if (unz_err != UNZ_OK || unzOpenCurrentFile(pkg) != UNZ_OK) { unzClose(pkg); ERR_FAIL_V(NULL); }; return pkg; };
int FileSystemZip::GetFileSize( std::string fileName ) { int err = UNZ_OK; unz_file_info file_info; char filename_inzip[512]; zipCacheMap::iterator itor = m_cache.find(m_rootDir+fileName); if (itor == m_cache.end()) { return -1; //not found in this zip } err = unzGoToFilePos(m_unzf, &itor->second.unzfilepos); if (err!=UNZ_OK) { LogError("error %d with unzGoToFilePos in unzGetCurrentFileInfo",err); return -1; } err = unzGetCurrentFileInfo(m_unzf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzGetCurrentFileInfo",err); return false; } // LogMsg("File is filesize %d", (int)file_info.uncompressed_size ); return (int)file_info.uncompressed_size; }
nglIZip* nglZipFS::GetStream(const nglZipPath& rPath) { Node* pNode = mRoot.Find(rPath); if (!pNode) return NULL; if (!pNode->mIsLeaf) return NULL; unz_file_pos file_pos; file_pos.num_of_file = pNode->mNumOfFile; file_pos.pos_in_zip_directory = pNode->mPosInZipDirectory; if (unzGoToFilePos(mpPrivate->mZip, &file_pos) != UNZ_OK) return NULL; if (unzOpenCurrentFile(mpPrivate->mZip) != UNZ_OK) return NULL; void* pUnzip = unzGetCurrentFile(mpPrivate->mZip); if (!pUnzip) return NULL; return new nglIZip(this, pUnzip, pNode->mSize, pNode->mNumOfFile, pNode->mPosInZipDirectory); }
// To simplify things, files are always read completely into memory from // the zip-file, since zlib does not provide any way of reading more // than one file at a time bool CZipArchive::GetFile(unsigned int fid, std::vector<unsigned char>& buffer) { // Prevent opening files on missing/invalid archives if (!zip) { return false; } // assert(IsFileId(fid)); unzGoToFilePos(zip, &fileData[fid].fp); unz_file_info fi; unzGetCurrentFileInfo(zip, &fi, NULL, 0, NULL, 0, NULL, 0); if (unzOpenCurrentFile(zip) != UNZ_OK) { return false; } buffer.resize(fi.uncompressed_size); bool ret = true; if (!buffer.empty() && unzReadCurrentFile(zip, &buffer[0], fi.uncompressed_size) != (int)fi.uncompressed_size) { ret = false; } if (unzCloseCurrentFile(zip) == UNZ_CRCERROR) { ret = false; } if (!ret) { buffer.clear(); } return ret; }
MemoryData ZipReader::ReadAllData(StringRef fileName)const { MemoryData result; if (mZipFile==nullptr||fileName.IsEmpty()) { return result; } const ZipFileInfo* zipEntryInfo=mFileDict.TryGetByOtherKey(fileName,fileName.HashCode()); if (zipEntryInfo==nullptr) { return result; } int err = unzGoToFilePos(mZipFile, (unz_file_pos*)&zipEntryInfo->Pos); if (err!=UNZ_OK) { return result; } err = unzOpenCurrentFile(mZipFile); if (err!=UNZ_OK) { return result; } result=MemoryData::Alloc(zipEntryInfo->UncompressedSize); int readSize = unzReadCurrentFile(mZipFile, result.MutableData(), (uint)zipEntryInfo->UncompressedSize); Log::Assert(readSize==(int)zipEntryInfo->UncompressedSize,"Invalid zip file size."); //readSize could be 0 because we may have zero file such as "StringTable-enus.bin" unzCloseCurrentFile(mZipFile); return result; }
bool zip::ZipArchiveInput::ReadFile( String_t const& fileName, Byte_t*& pMemoryBlock, size_t& size ) { String_t fileNameKey = fileName; if( !m_caseSensitive ) for (size_t i = 0; i < fileNameKey.size(); ++i ) fileNameKey[i] = _ttolower( fileNameKey[i] ); NameToEntry_t::const_iterator keyValue = m_nameToEntry.find( fileNameKey ); if( keyValue == m_nameToEntry.end() ) { m_errorMessage << "file " << fileNameKey << " not found in the zip index" << std::endl; return false; } ZipEntry const& zipEntry = keyValue->second; unz_file_pos pos; pos.pos_in_zip_directory = zipEntry.pos_in_zip_directory; pos.num_of_file = zipEntry.num_of_file; int err = unzGoToFilePos( uf, &pos ); if( err != UNZ_OK ) { m_errorMessage << "Can't go to file " << fileName << std::endl; return false; } return ReadCurrentFile( fileName, pMemoryBlock, size ); }
fileHandleZip(const file_entry *entry):_entry(entry) { int r = 0; r = unzGoToFilePos(entry->zp, const_cast<unz_file_pos*>(&entry->pos)); OX_ASSERT(r == UNZ_OK); r = unzOpenCurrentFile(entry->zp); OX_ASSERT(r == UNZ_OK); }
void fillBuffer() { int readSize = fileData.size; if(unzGoToFilePos(zipData->fileId, &fileData.filePosition) != UNZ_OK) return; if(unzOpenCurrentFile(zipData->fileId) != UNZ_OK) return; int bytes = unzReadCurrentFile(zipData->fileId, &buffer[0], readSize); assert(bytes == readSize); unzCloseCurrentFile(zipData->fileId); }
bool UnzipBase::__extract(const mbs& filename,vector<char>& buffer,bool case_sens,bool raw,int& method,int& level) { if(!_handle) return false; if(!filename.length()) return false; __int64 index; if(case_sens) { hash_map<mbs,__int64>::iterator iter=_indices.find(filename); if(iter==_indices.end()) return false; index=iter->second; } else { mbs filename2=TOLOWER(filename); hash_map<mbs,__int64>::iterator iter=_indices_ci.find(filename2); if(iter==_indices_ci.end()) return false; index=iter->second; } unz_file_info file_info; if(unzGoToFilePos(_handle,(unz_file_pos*)&index)!=UNZ_OK) return false; if(unzGetCurrentFileInfo(_handle,&file_info,0,0,0,0,0,0)!=UNZ_OK) return false; if(unzOpenCurrentFile2(_handle,&method,&level,raw?1:0)!=UNZ_OK) return false; buffer.resize(file_info.uncompressed_size); int ret; int decomp = 0; if(buffer.size()) while(decomp != file_info.uncompressed_size) { ret = unzReadCurrentFile(_handle,&buffer[decomp], (unsigned int)buffer.size() - decomp); if(ret > 0) decomp += ret; else if(ret <= 0) break; } unzCloseCurrentFile(_handle); return (decomp==file_info.uncompressed_size); }
unsigned char *ZipFile::getFileData(const std::string &fileName, unsigned long *pSize) { unsigned char * pBuffer = NULL; if (pSize) { *pSize = 0; } CCLog("zip File size %s, %d", fileName.c_str(), pSize); do { CCLog("condition %x %d", m_data->zipFile, fileName.empty()); CC_BREAK_IF(!m_data->zipFile); CC_BREAK_IF(fileName.empty()); ZipFilePrivate::FileListContainer::const_iterator it = m_data->fileList.find(fileName); //文件名称编码的问题? utf8 和 gb 编码? CCLog("fileList fileName %s find? %d", fileName.c_str(), it!=m_data->fileList.end()); CC_BREAK_IF(it == m_data->fileList.end()); ZipEntryInfo fileInfo = it->second; int nRet = unzGoToFilePos(m_data->zipFile, &fileInfo.pos); CC_BREAK_IF(UNZ_OK != nRet); nRet = unzOpenCurrentFile(m_data->zipFile); CC_BREAK_IF(UNZ_OK != nRet); pBuffer = new unsigned char[fileInfo.uncompressed_size]; int nSize = 0; nSize = unzReadCurrentFile(m_data->zipFile, pBuffer, fileInfo.uncompressed_size); CCAssert(nSize == 0 || nSize == (int)fileInfo.uncompressed_size, "the file size is wrong"); if (pSize) { *pSize = fileInfo.uncompressed_size; } unzCloseCurrentFile(m_data->zipFile); } while (0); CCLog("pBuffer Size %x", pBuffer); return pBuffer; }
bool readEntry(const file_entry *entry, file::buffer &bf) { bf.data.resize(0); int r = unzGoToFilePos(entry->zp, const_cast<unz_file_pos*>(&entry->pos)); OX_ASSERT(r == UNZ_OK); unz_file_info file_info; r = unzGetCurrentFileInfo(entry->zp, &file_info, 0, 0, 0, 0, 0, 0); OX_ASSERT(r == UNZ_OK); unzOpenCurrentFile(entry->zp); bf.data.resize(file_info.uncompressed_size); r = unzReadCurrentFile(entry->zp, &bf.data.front(), (int)bf.data.size()); OX_ASSERT(r == (int)file_info.uncompressed_size); unzCloseCurrentFile(entry->zp); return true; }
// To simplify things, files are always read completely into memory from the zipfile, since zlib does not // provide any way of reading more than one file at a time ABOpenFile_t* CArchiveZip::GetEntireFile(const std::string& fName) { // Don't allow opening files on missing/invalid archives if (!zip) return NULL; std::string fileName = StringToLower(fName); //if (unzLocateFile(zip, fileName.c_str(), 2) != UNZ_OK) // return 0; if (fileData.find(fileName) == fileData.end()) return NULL; FileData fd = fileData[fileName]; unzGoToFilePos(zip, &fileData[fileName].fp); unz_file_info fi; unzGetCurrentFileInfo(zip, &fi, NULL, 0, NULL, 0, NULL, 0); ABOpenFile_t* of = new ABOpenFile_t; of->pos = 0; of->size = fi.uncompressed_size; of->data = (char*)malloc(of->size); // If anything fails, we abort try { if (unzOpenCurrentFile(zip) != UNZ_OK) throw zip_exception(); if (unzReadCurrentFile(zip, of->data, of->size) < 0) throw zip_exception(); if (unzCloseCurrentFile(zip) == UNZ_CRCERROR) throw zip_exception(); } catch (zip_exception) { free(of->data); delete of; return NULL; } return of; }
bool ZipArchiveFile::Open() { this->mutex->lock(); if (unzGoToFilePos(archive, &position) != UNZ_OK) { std::cerr << "ZipArchive: Failed to go to file position" << std::endl; this->mutex->unlock(); return false; } if (unzOpenCurrentFile(archive) != UNZ_OK) { std::cerr << "ZipArchive: Failed to open current file" << std::endl; this->mutex->unlock(); return false; } return true; }
nglFileOffset nglZipFS::SetPos (void* pUnzip, nglFileOffset Where, nglIZip* pFile) { unzSetCurrentFile(mpPrivate->mZip, pUnzip); char dummy[1024]; nglFileOffset Pos = GetPos(pUnzip); if (Where < Pos) { unzCloseCurrentFile(mpPrivate->mZip); unz_file_pos file_pos; file_pos.num_of_file = pFile->mNumOfFile; file_pos.pos_in_zip_directory = pFile->mPosInZipDirectory; unzGoToFilePos(mpPrivate->mZip, &file_pos); if (unzOpenCurrentFile(mpPrivate->mZip) != UNZ_OK) return 0; pUnzip = unzGetCurrentFile(mpPrivate->mZip); if (!pUnzip) return 0; pFile->SetRef(pUnzip); Pos = 0; } Where -= Pos; while (Where > 0) { nglFileOffset size = MIN(Where, 1024); nglSize res = Read(pUnzip, dummy, (long)size, 1, eEndianNative); if (res <= 0) // An Error occured return GetPos(pUnzip); Where -= res; } return GetPos(pUnzip); }
KDubyte* ZipFile::getFileData ( const std::string& sFileName, KDsize* pSize ) { KDubyte* pBuffer = KD_NULL; if ( pSize ) { *pSize = 0; } do { CC_BREAK_IF ( !m_pData->zipFile ); CC_BREAK_IF ( sFileName.empty ( ) ); ZipFilePrivate::FileListContainer::const_iterator it = m_pData->fileList.find ( sFileName ); CC_BREAK_IF ( it == m_pData->fileList.end ( ) ); ZipEntryInfo tFileInfo = it->second; KDint nRet = unzGoToFilePos ( m_pData->zipFile, &tFileInfo.pos ); CC_BREAK_IF ( UNZ_OK != nRet ); nRet = unzOpenCurrentFile ( m_pData->zipFile ); CC_BREAK_IF ( UNZ_OK != nRet ); pBuffer = new KDubyte [ tFileInfo.uncompressed_size ]; KDint nSize = 0; nSize = unzReadCurrentFile ( m_pData->zipFile, pBuffer, tFileInfo.uncompressed_size ); CCAssert ( nSize == 0 || nSize == (KDint) tFileInfo.uncompressed_size, "the file size is wrong" ); if ( pSize ) { *pSize = tFileInfo.uncompressed_size; } unzCloseCurrentFile ( m_pData->zipFile ); } while ( 0 ); return pBuffer; }
unsigned char* ZipFile::getFileData(const std::string& fileName, unsigned long* pSize) { unsigned char* pBuffer = NULL; if (pSize) { *pSize = 0; } do { CC_BREAK_IF(!m_data->zipFile); CC_BREAK_IF(fileName.empty()); std::string file(fileName); //str_tolower(file); ZipFilePrivate::FileListContainer::const_iterator it = m_data->fileList.find(file); CC_BREAK_IF(it == m_data->fileList.end()); ZipEntryInfo fileInfo = it->second; int nRet = unzGoToFilePos(m_data->zipFile, &fileInfo.pos); CC_BREAK_IF(UNZ_OK != nRet); nRet = unzOpenCurrentFile(m_data->zipFile); CC_BREAK_IF(UNZ_OK != nRet); pBuffer = new unsigned char[fileInfo.uncompressed_size]; int CC_UNUSED nSize = unzReadCurrentFile(m_data->zipFile, pBuffer, (unsigned int)fileInfo.uncompressed_size); CCAssert(nSize == 0 || nSize == (int)fileInfo.uncompressed_size, "the file size is wrong"); if (pSize) { *pSize = fileInfo.uncompressed_size; } unzCloseCurrentFile(m_data->zipFile); } while (0); return pBuffer; }
fileHandleZipStreaming(const file_entry* entry, const Zips& z): _cpos(0) { int r = 0; r = unzGoToFilePos(entry->zp, const_cast<unz_file_pos*>(&entry->pos)); OX_ASSERT(r == UNZ_OK); r = unzOpenCurrentFile(entry->zp); OX_ASSERT(r == UNZ_OK); void* ptr; r = unzRealTell(entry->zp, &_pos, &_size, &ptr); OX_ASSERT(r == UNZ_OK); zlib_filefunc_def* f = (zlib_filefunc_def*)ptr; const char* ssss = z.getZipFileName((int)(size_t)f->opaque); _h = file::open(ssss, "rb"); file::seek(_h, static_cast<unsigned int>(_pos), SEEK_SET); unzCloseCurrentFile(entry->zp); }
unsigned char* CCZipFile::getFileDataNoOrder(const char *fileName, unsigned long *pSize) { unsigned char * pBuffer = NULL; if (pSize) { *pSize = 0; } do { CC_BREAK_IF(!m_zipFile); CC_BREAK_IF(m_fileList.empty()); std::map<std::string, struct __ZipEntryInfo>::const_iterator it = m_fileList.find(fileName); CC_BREAK_IF(it == m_fileList.end()); __ZipEntryInfo fileInfo = it->second; int nRet = unzGoToFilePos(m_zipFile, &fileInfo.pos); CC_BREAK_IF(UNZ_OK != nRet); nRet = unzOpenCurrentFile(m_zipFile); CC_BREAK_IF(UNZ_OK != nRet); //MARK unfinish process big file pBuffer = new unsigned char[fileInfo.uncompressed_size]; int CC_UNUSED nSize = unzReadCurrentFile(m_zipFile, pBuffer, fileInfo.uncompressed_size); CCAssert(nSize == 0 || nSize == (int)fileInfo.uncompressed_size, "the file size is wrong"); if (pSize) { *pSize = fileInfo.uncompressed_size; } unzCloseCurrentFile(m_zipFile); } while (0); return pBuffer; }
char* Zip::getFileData(const char* filename, unsigned long& size) { char * pBuffer = NULL; auto it = _files.find(filename); if (it == _files.end()) return NULL; ZipEntryInfo fileInfo = it->second; int nRet = unzGoToFilePos(_zipFile, &fileInfo.pos); if (UNZ_OK != nRet) return NULL; nRet = unzOpenCurrentFile(_zipFile); if (UNZ_OK != nRet) return NULL; pBuffer = new char[fileInfo.uncompressed_size]; unzReadCurrentFile(_zipFile, pBuffer, fileInfo.uncompressed_size); size = fileInfo.uncompressed_size; unzCloseCurrentFile(_zipFile); return pBuffer; }
bool CZipArchive::ExtractFile(std::size_t index) //---------------------------------------------- { if(index >= contents.size()) { return false; } data.clear(); unz_file_pos bestFile; unz_file_info info; bestFile.pos_in_zip_directory = static_cast<uLong>(contents[index].cookie1); bestFile.num_of_file = static_cast<uLong>(contents[index].cookie2); if(unzGoToFilePos(zipFile, &bestFile) == UNZ_OK && unzOpenCurrentFile(zipFile) == UNZ_OK) { unzGetCurrentFileInfo(zipFile, &info, nullptr, 0, nullptr, 0, nullptr, 0); try { data.resize(info.uncompressed_size); } catch(...) { unzCloseCurrentFile(zipFile); return false; } unzReadCurrentFile(zipFile, &data[0], info.uncompressed_size); unzCloseCurrentFile(zipFile); return true; } return false; }
byte * FileSystemZip::Get( string fileName, int *pSizeOut ) { zipCacheMap::iterator itor = m_cache.find(m_rootDir+fileName); if (itor == m_cache.end()) { return NULL; //not found in this zip //bingo! } int err = UNZ_OK; err = unzGoToFilePos(m_uf, &itor->second.m_filepos); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzGoToFilePos",err); return NULL; } /* //old slow way of locating a file if (unzLocateFile(m_uf,(m_rootDir+fileName).c_str(),CASESENSITIVITY)!=UNZ_OK) { return NULL; } */ unz_file_info file_info; char st_filename_inzip[512]; err = unzGetCurrentFileInfo(m_uf,&file_info,st_filename_inzip,sizeof(st_filename_inzip),NULL,0,NULL,0); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzGetCurrentFileInfo",err); return NULL; } //let's allocate our own memory and pass the pointer back to them. byte *pBytes = new byte[file_info.uncompressed_size+1]; //the extra is because I will add a null later, helps when processing //text files and can't hurt if (pBytes) { //memory allocated *pSizeOut = file_info.uncompressed_size; pBytes[file_info.uncompressed_size] = 0; } else { LogError("Couldn't allocate the required %d bytes to unzip into.", file_info.uncompressed_size+1); return NULL; } err = unzOpenCurrentFile(m_uf); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzOpenCurrentFile",err); return NULL; } err = unzReadCurrentFile(m_uf,pBytes,file_info.uncompressed_size); if (err<0) { LogError("error %d with zipfile in unzReadCurrentFile",err); return NULL; } err = unzCloseCurrentFile(m_uf); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzCloseCurrentFile",err); return NULL; } return pBytes; }
byte* FileSystemZip::Get_unz( std::string fileName, int *pSizeOut ) { int err = UNZ_OK; char filename_inzip[512]; unz_file_info file_info; zipCacheMap::iterator itor = m_cache.find(m_rootDir+fileName); byte* pBytes; if (itor == m_cache.end()) { return NULL; //not found in this zip //bingo! } err = unzGoToFilePos(m_unzf, &itor->second.unzfilepos); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzGoToFilePos",err); return NULL; } err = unzGetCurrentFileInfo(m_unzf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzGetCurrentFileInfo",err); return NULL; } //let's allocate our own memory and pass the pointer back to them. pBytes = new byte[file_info.uncompressed_size+1]; //the extra is because I will add a null later, helps when processing if (pBytes) { //memory allocated *pSizeOut = file_info.uncompressed_size; pBytes[file_info.uncompressed_size] = 0; } else { LogError("Couldn't allocate the required %d bytes to unzip into.", file_info.uncompressed_size+1); return NULL; } err = unzOpenCurrentFile(m_unzf); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzOpenCurrentFile",err); return NULL; } err = unzReadCurrentFile(m_unzf,pBytes,file_info.uncompressed_size); if (err<0) { LogError("error %d with zipfile in unzReadCurrentFile",err); return NULL; } err = unzCloseCurrentFile(m_unzf); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzCloseCurrentFile",err); return NULL; } return pBytes; }
CZipStream::CZipStream(const std::string & archive, unz_file_pos filepos) { file = unzOpen(archive.c_str()); unzGoToFilePos(file, &filepos); unzOpenCurrentFile(file); }
int load_game_scripts(lua_State* L, const char* zipfile) { size_t size = 0; unsigned char* filedata = s_read(zipfile, &size, 0); if (!filedata) { fprintf(stderr, "unable to read zipfile = %s\n", zipfile); return 1; } unzFile unzfile = unzOpenBuffer(filedata, size); if(!unzfile) { fprintf(stderr, "open zip from buffer failed.\n"); return 1; } lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); char filename[1024] = ""; int err = unzGoToFirstFile(unzfile); if (err) { fprintf(stderr, "go to first file failed"); return 1; } bool succeed = true; while (true) { unz_file_info info; err = unzGetCurrentFileInfo(unzfile, &info, filename, 1024, NULL, 0, NULL, 0); if (err) { fprintf(stderr, "get current file info failed, filename = %s\n", filename); succeed = false; break; } unz_file_pos file_pos; err = unzGetFilePos(unzfile, &file_pos); err = unzGoToFilePos(unzfile, &file_pos); err = unzOpenCurrentFile(unzfile); unsigned long size = info.uncompressed_size; unsigned char* buffer = s_malloc(size); unsigned int readed = unzReadCurrentFile(unzfile, buffer, (unsigned int)size); if(readed != size) { succeed = false; fprintf(stderr, "read zip file failed? error size, required = %ld, readed = %d, filename = %s\n", size, readed, filename); goto error; } err = luaL_loadbuffer(L, (const char*)buffer, size, filename); if(err) { fprintf(stderr, "error loadL_loadbuffer, filename = %s\n", filename); goto error; } lua_setfield(L, -2, filename); if(unzGoToNextFile(unzfile) == UNZ_END_OF_LIST_OF_FILE) { succeed = true; break; } unzCloseCurrentFile(unzfile); s_free(buffer); continue; error: succeed = false; unzCloseCurrentFile(unzfile); s_free(buffer); break; } lua_pop(L, -1); return succeed ? 1 : 0; }