fix Unzip::extract failing if the extractable file is empty

This commit is contained in:
HJfod 2023-01-31 21:31:41 +02:00
parent 049ff650e4
commit fa94a56ea0

View file

@ -295,6 +295,11 @@ public:
.expect("Unable to open entry (code {error})") .expect("Unable to open entry (code {error})")
); );
// if the file is empty, its data is empty (duh)
if (!entry.uncompressedSize) {
return Ok(ByteVector());
}
ByteVector res; ByteVector res;
res.resize(entry.uncompressedSize); res.resize(entry.uncompressedSize);
auto read = mz_zip_entry_read(m_handle, res.data(), entry.uncompressedSize); auto read = mz_zip_entry_read(m_handle, res.data(), entry.uncompressedSize);
@ -421,11 +426,11 @@ bool Unzip::hasEntry(Path const& name) {
} }
Result<ByteVector> Unzip::extract(Path const& name) { Result<ByteVector> Unzip::extract(Path const& name) {
return m_impl->extract(name); return m_impl->extract(name).expect("{error} (entry {})", name.string());
} }
Result<> Unzip::extractTo(Path const& name, Path const& path) { Result<> Unzip::extractTo(Path const& name, Path const& path) {
GEODE_UNWRAP_INTO(auto bytes, m_impl->extract(name)); GEODE_UNWRAP_INTO(auto bytes, m_impl->extract(name).expect("{error} (entry {})", name.string()));
// create containing directories for target path // create containing directories for target path
if (path.has_parent_path()) { if (path.has_parent_path()) {
GEODE_UNWRAP(file::createDirectoryAll(path.parent_path())); GEODE_UNWRAP(file::createDirectoryAll(path.parent_path()));