Can not unzip file with cocos::ZipFile(filePath)

We are trying to download assets from the server and want to unzip the Zip file, it was working before but not it’s not working here is the sample code can anyone help us, thanks

void HelloWorld::startDownload() {


        log("One Download is in progress\n");
    //todo -> url of Zip file
    std::string url = "";
    filePath = FileUtils::getInstance()->getWritablePath() + "";

    _downloader = new (std::nothrow) network::Downloader();

    _downloader->onTaskProgress = ([this](const network::DownloadTask& task, int64_t bytesReceived, int64_t totalBytesReceived, int64_t totalBytesExpected) {
        CCLOG("download progress %.0f%%", (float) totalBytesReceived * 100.0 / totalBytesExpected );


    _downloader->onFileTaskSuccess = ([this](const network::DownloadTask& task) {
        CCLOG("downloaded success");

        auto def = UserDefault::getInstance();
        def->setBoolForKey(std::to_string(downloadingGameNumber).c_str(), true);


        delete _downloader;
        _downloader = nullptr;
        _task = nullptr;
        _downloadRunning = false;


    _downloader->onTaskError = ([](const network::DownloadTask& task, int errorCode, int errorCodeInternal, const std::string& errorStr) {
        CCLOG("downloading error %s", errorStr.c_str());

    _task = _downloader->createDownloadFileTask(url, filePath);
    log("file storage at : %s\n",_task->storagePath.c_str());

    _downloadRunning = true;

    CCLOG("download started");

void HelloWorld::upZip()

    cocos2d::ZipFile zFile = cocos2d::ZipFile(filePath);

    std::string fileName = zFile.getFirstFilename();

    std::string file = fileName;

    ssize_t filesize;
    unsigned char* data = zFile.getFileData(fileName, &filesize);

    std::string directoryName = cocos2d::FileUtils::getInstance()->getWritablePath() + "data/slotgame/";

    if (!cocos2d::FileUtils::getInstance()->isDirectoryExist(directoryName))

    while (data != nullptr)
        std::string fullFileName = directoryName + file;

        log("filename DIR : %s\n",fullFileName.c_str());

        if(fullFileName[fullFileName.size()-1] == '/'){


            fileName = zFile.getNextFilename();
            file = fileName;

            data = zFile.getFileData(fileName, &filesize);

        FILE *fp = fopen(fullFileName.c_str(), "wb");

        if (fp)
            fwrite(data, 1, filesize, fp);

        fileName = zFile.getNextFilename();
        file = fileName;

        data = zFile.getFileData(fileName, &filesize);



What is happening?

How far do you get in this code?

what version of cocos2d-x?

what operating system?

any errors in the console?

we have one zip file in server we wants to download it and then unzip it and wants to assets,

it was working before we have tested, now it’s downloading successfully, but

from the line it’s returning null, means it can’t find out zip even though we are providing exactly path,

cocos2dx 3.17.1
windows 10
no error it’s just returning null zip file

What does filePath contain? just null?

Can you verify the file is even where it was downloaded to?

What change did you make to where it worked and then now doesn’t work? Did you update cocos2d-x versions? From what version did you upgrade from?

yeah we have checked file there only, it just not unzipping.

we were using 3.17.0 and upgraded to 3.17.1

I don’t see any GitHub issues already open about this. You should make one.

If you revert to 3.17.0 does it start working again?

we have not tried with 3.17.0 after this issue, and have you tried this code, please check once and see you can help us :slight_smile:

So it was working in 3.17.0 is what I am asking?

yeah it was :slight_smile:

my advice is to go back to 3.17.0 for now. If this is a bug it wont be fixed right away, AFAIK.

thank you, I will try if you find out solution let us know

@parth3535 I’m almost certain it’s this issue and the fix is to update the cocos2d-x 3rd party libraries. Use v3-deps-156 since it seems to have worked for others.


@R101. Nice eyes, I didn’t see that. Thank you.

1 Like

thanks we will try it and let you know whatever happens

It’s an issue I came across when I updated my project to use v3.17.1 too, so it’s still fresh in my mind. :slight_smile: A few others seem to have come across it when they were trying to use OBB files on Android, but it’s a more general issue related to the 3rd party zip library.

@R101. I think we need to let users know this is a must step:

1 Like

Couldn’t agree more. I think there are several posts about this already from users asking for help. They won’t see it as an issue on Github either since it doesn’t show closed issues by default.

1 Like

i was gonna ask for this

we have run the command from coco2dx root

and it downloaded what should we do now? will it work

I don’t know if any versions prior had this fix. But download this and extract it overtop