MCPcopy Create free account
hub / github.com/axmolengine/axmol / getContents

Method getContents

core/platform/FileUtils.cpp:578–612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

576}
577#endif
578FileUtils::Status FileUtils::getContents(std::string_view filename, ResizableBuffer* buffer) const
579{
580 if (filename.empty())
581 return Status::NotExists;
582
583 auto fileUtils = FileUtils::getInstance();
584
585 const auto fullPath = fileUtils->fullPathForFilename(filename);
586
587 FileStream fileStream;
588 fileStream.open(fullPath, IFileStream::Mode::READ);
589 if (!fileStream)
590 return Status::OpenFailed;
591
592 const auto size = fileStream.size();
593 if (size < 0)
594 {
595 return Status::ObtainSizeFailed;
596 }
597
598 if (size > ULONG_MAX)
599 {
600 return Status::TooLarge;
601 }
602
603 buffer->resize((size_t)size);
604 const auto sizeRead = fileStream.read(buffer->buffer(), (unsigned)size);
605 if (sizeRead < size)
606 {
607 buffer->resize(sizeRead);
608 return Status::ReadFailed;
609 }
610
611 return Status::OK;
612}
613#ifndef AX_CORE_PROFILE
614void FileUtils::writeValueMapToFile(ValueMap dict, std::string_view fullPath, std::function<void(bool)> callback) const
615{

Callers 5

loadMethod · 0.80
FileUtilsTests.cppFile · 0.80
addPackageMethod · 0.80
readFileContentFunction · 0.80
loadDragonBonesDataMethod · 0.80

Calls 8

getInstanceFunction · 0.85
fullPathForFilenameMethod · 0.80
emptyMethod · 0.45
openMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
readMethod · 0.45
bufferMethod · 0.45

Tested by

no test coverage detected