• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FILE_CACHE_H_
17 #define FILE_CACHE_H_
18 
19 #include <algorithm>
20 #include <climits>
21 #include <cstdint>
22 #include <fstream>
23 #include <string>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include <unordered_map>
27 
28 #include "logging.h"
29 #include "securec.h"
30 
31 class FileCache {
32 public:
33     FileCache(const std::string &path);
34     ~FileCache();
35 
36     bool Open(const std::string& name);
37 
38     long Write(char* bytes, int32_t len);
39 
40     long Read(char* buff);
41 
42     bool Close();
43 
44 private:
45     std::string path_;
46     FILE* fp_;
47     std::unordered_map<uint64_t, uint64_t> size_;
48 };
49 
50 #endif // !FILE_CACHE_H_