MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / readFile

Method readFile

TheForceEngine/TFE_Archive/zipArchive.cpp:214–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212}
213
214size_t ZipArchive::readFile(void* data, size_t size)
215{
216 if (m_curFile == INVALID_FILE) { return 0u; }
217 if (size == 0) { size = m_entries[m_curFile].length; }
218
219 const size_t sizeToRead = std::min(size, m_entries[m_curFile].length);
220 // The fast path is to just read the entire entry into the provided memory, avoiding the extra memcopy.
221 // This is only done if we are reading the entire file and there is no offset.
222 if (m_fileOffset == 0 && sizeToRead == m_entries[m_curFile].length)
223 {
224 m_fileOffset += (s32)sizeToRead;
225 s64 actualSizeRead = zip_entry_noallocread((struct zip_t*)m_fileHandle, data, sizeToRead);
226 if (actualSizeRead <= 0)
227 {
228 return 0u;
229 }
230 return size_t(actualSizeRead);
231 }
232
233 // Otherwise go through the slower path - a one time decompression and read, followed
234 // by memcopying the data into the output as needed.
235 if (!m_entryRead)
236 {
237 // Read the whole entry into temporary memory.
238 assert(m_tempBufferSize >= m_entries[m_curFile].length);
239 if (zip_entry_noallocread((struct zip_t*)m_fileHandle, m_tempBuffer, m_entries[m_curFile].length) <= 0)
240 {
241 return 0u;
242 }
243 m_entryRead = true;
244 }
245 // Then copy the section we want into the output.
246 memcpy(data, m_tempBuffer + m_fileOffset, sizeToRead);
247 m_fileOffset += (s32)sizeToRead;
248 return sizeToRead;
249}
250
251bool ZipArchive::seekFile(s32 offset, s32 origin)
252{

Callers 15

readAssetFromArchiveFunction · 0.45
loadEditorLevelPreviewFunction · 0.45
loadEditorFrameFunction · 0.45
loadEditorObj3DFunction · 0.45
loadEditorTextureFunction · 0.45
loadPaletteAsTextureFunction · 0.45
loadEditorSpriteFunction · 0.45
addPaletteFunction · 0.45
preprocessAssetsFunction · 0.45
extractArchiveFunction · 0.45
updateAssetListFunction · 0.45
exportSelectedFunction · 0.45

Calls 2

minFunction · 0.85
zip_entry_noallocreadFunction · 0.85

Tested by

no test coverage detected