| 576 | } |
| 577 | #endif |
| 578 | FileUtils::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 |
| 614 | void FileUtils::writeValueMapToFile(ValueMap dict, std::string_view fullPath, std::function<void(bool)> callback) const |
| 615 | { |
no test coverage detected