MNN/source/core/FileLoader.hpp

47 lines
1014 B
C++
Raw Normal View History

//
// FileLoader.hpp
// MNN
//
// Created by MNN on 2019/07/04.
// Copyright © 2018, Alibaba Group Holding Limited
//
2024-04-19 11:58:21 +08:00
#ifndef MNN_FileLoader_hpp
#define MNN_FileLoader_hpp
#include <vector>
2021-09-18 15:52:30 +08:00
#include <mutex>
2019-12-27 22:16:57 +08:00
#include "core/AutoStorage.h"
namespace MNN {
class MNN_PUBLIC FileLoader {
public:
2024-04-19 11:58:21 +08:00
FileLoader(const char* file, bool init = false);
~FileLoader();
bool read();
2021-09-18 15:52:30 +08:00
2022-01-04 10:50:40 +08:00
static bool write(const char* filePath, std::pair<const void*, size_t> cacheInfo);
bool valid() const {
return mFile != nullptr;
}
inline size_t size() const {
return mTotalSize;
}
bool merge(AutoStorage<uint8_t>& buffer);
2022-12-30 15:18:58 +08:00
int offset(int64_t offset);
bool read(char* buffer, int64_t size);
private:
2024-04-19 11:58:21 +08:00
void _init();
std::vector<std::pair<size_t, void*>> mBlocks;
FILE* mFile = nullptr;
static const int gCacheSize = 4096;
size_t mTotalSize = 0;
2024-04-19 11:58:21 +08:00
std::string mFilePath;
bool mInited = false;
};
} // namespace MNN
2024-04-19 11:58:21 +08:00
#endif