ZIPReader fails when reading files

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CosmoXD

Hello, I’m creating an updater for my game but when I try to read the ZIP file using the class ZIPReader it just returns Error.Failed.

Here’s the segment of the code that fails:

const string downloadPath = "user://update.zip";
FileAccess file = FileAccess.Open(downloadPath, FileAccess.ModeFlags.Write);
file.StoreBuffer(body);

GD.Print("Download completed!");

ZIPReader zip = new ZIPReader();
Error openProcess = zip.Open(downloadPath);

if (openProcess != Error.Ok)
{
    GD.PrintErr("Can't open the 'update.zip' file!");
    GD.PrintErr($"{openProcess.ToString()}");
    goto install_failed;
}

I’ve tried to open the downloaded zip file outside the app and I can open it correctly.

:bust_in_silhouette: Reply From: CosmoXD

Well, I’ve fixed this by calling Flush after storing the buffer in the file.

FileAccess file = FileAccess.Open(path, FileAccess.ModeFlags.Write);
file.StoreBuffer(buffer);
file.Flush();

This may be a bug (There’s an issue already ZIPReader with HTTPRequest doesn't work consistently in seemingly equivalent code · Issue #68614 · godotengine/godot · GitHub) so maybe doing this isn’t necessary in future builds.