• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 OHOS_ABILITY_BASE_FILE_MAPPER_H
17 #define OHOS_ABILITY_BASE_FILE_MAPPER_H
18 
19 #include <memory>
20 #include <string>
21 
22 namespace panda {
23 namespace ecmascript {
24 class ZipFileReader;
25 enum class FileMapperType {
26     NORMAL_MEM,
27     SHARED_MMAP,
28     SAFE_ABC
29 };
30 class FileMapper {
31 public:
32     FileMapper();
33     FileMapper(FileMapper &) = delete;
34     void operator=(FileMapper &) = delete;
35     ~FileMapper();
36 
37     bool CreateFileMapper(const std::string &fileName, bool compress,
38         int32_t fd, size_t offset, size_t len, FileMapperType type);
39 
40     bool CreateFileMapper(std::shared_ptr<ZipFileReader> fileReader, const std::string &fileName,
41         size_t offset, size_t len, bool compress);
42 
43     bool IsCompressed();
44     uint8_t* GetDataPtr();
45     size_t GetDataLen();
46     std::string GetFileName();
47     int32_t GetOffset();
48 private:
49     std::string fileName_;
50     bool isCompressed = false;
51 
52     std::unique_ptr<uint8_t[]> dataPtr_ = nullptr;
53     size_t dataLen_ = 0;
54     size_t offset_ = 0;
55 
56     uint8_t* basePtr_ = nullptr;
57     uint8_t* usePtr_ = nullptr;
58     size_t baseLen_ = 0;
59     FileMapperType type_ = FileMapperType::NORMAL_MEM;
60 };
61 }  // namespace AbilityBase
62 }  // namespace OHOS
63 #endif  // OHOS_ABILITY_BASE_FILE_MAPPER_H