in source/neuropod/internal/neuropod_loader.cc [116:163]
std::unique_ptr<std::istream> get_istream_for_file(const std::string &path) override
{
auto out = stdx::make_unique<std::stringstream>();
// Find the file we're looking for
auto err = mz_zip_reader_locate_entry(zip_reader_, path.c_str(), 1);
if (err != MZ_OK)
{
SPDLOG_TRACE("Couldn't find file in zip: {}", path);
return nullptr;
}
// Open it
err = mz_zip_reader_entry_open(zip_reader_);
if (err != MZ_OK)
{
SPDLOG_TRACE("Couldn't open file '{}' in zip file: {}", path, err);
return nullptr;
}
char buf[4096];
int32_t bytes_read = 0;
do
{
// Read chunks and write to the output stream
bytes_read = mz_zip_reader_entry_read(zip_reader_, buf, sizeof(buf));
if (bytes_read < 0)
{
err = bytes_read;
break;
}
out->write(buf, bytes_read);
} while (bytes_read > 0);
// Close the reader
mz_zip_reader_entry_close(zip_reader_);
// Make sure we correctly read the file
if (err != MZ_OK)
{
SPDLOG_TRACE("Error reading zip file entry: {}", err);
return nullptr;
}
return out;
}