MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / readDocument

Method readDocument

framework/serialization/providers/zipdataprovider.cpp:64–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62 return true;
63}
64bool ZipDataProvider::readDocument(const UString &filename, UString &result)
65{
66
67 auto it = fileLookup.find(filename);
68 if (it == fileLookup.end())
69 {
70 LogInfo("File \"%s\" not found in zip in zip \"%s\"", filename, zipPath);
71 return false;
72 }
73 unsigned int fileId = it->second;
74 mz_zip_archive_file_stat stat;
75 memset(&stat, 0, sizeof(stat));
76 if (!mz_zip_reader_file_stat(&archive, fileId, &stat))
77 {
78 LogWarning("Failed to stat file \"%s\" in zip \"%s\"", filename, zipPath);
79 return false;
80 }
81 if (stat.m_uncomp_size == 0)
82 {
83 LogInfo("Skipping %s - possibly a directory?", filename);
84 return false;
85 }
86
87 LogInfo("Reading %lu bytes for file \"%s\" in zip \"%s\"", (unsigned long)stat.m_uncomp_size,
88 filename, zipPath);
89
90 up<char[]> data(new char[(unsigned int)stat.m_uncomp_size]);
91 if (!mz_zip_reader_extract_to_mem(&archive, fileId, data.get(), (size_t)stat.m_uncomp_size, 0))
92 {
93 LogWarning("Failed to extract file \"%s\" in zip \"%s\"", filename, zipPath);
94 return false;
95 }
96
97 result = std::string(data.get(), (unsigned int)stat.m_uncomp_size);
98 return true;
99}
100bool ZipDataProvider::saveDocument(const UString &path, const UString &contents)
101{
102 if (!mz_zip_writer_add_mem(&archive, path.c_str(), contents.c_str(), contents.length(),

Callers 1

getRootMethod · 0.45

Calls 2

endMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected