| 1 | // Tencent is pleased to support the open source community by making ncnn available. |
| 2 | // |
| 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. |
| 4 | // |
| 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except |
| 6 | // in compliance with the License. You may obtain a copy of the License at |
| 7 | // |
| 8 | // https://opensource.org/licenses/BSD-3-Clause |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software distributed |
| 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | // specific language governing permissions and limitations under the License. |
| 14 | |
| 15 | #ifndef PNNX_STOREZIP_H |
| 16 | #define PNNX_STOREZIP_H |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | #include <map> |
| 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
| 23 | namespace pnnx { |
| 24 | |
| 25 | class StoreZipReader |
| 26 | { |
| 27 | public: |
| 28 | StoreZipReader(); |
| 29 | ~StoreZipReader(); |
| 30 | |
| 31 | int open(const std::string& path); |
| 32 | |
| 33 | std::vector<std::string> get_names() const; |
| 34 | |
| 35 | uint64_t get_file_size(const std::string& name) const; |
| 36 | |
| 37 | int read_file(const std::string& name, char* data); |
| 38 | |
| 39 | int close(); |
| 40 | |
| 41 | private: |
| 42 | FILE* fp; |
| 43 | |
| 44 | struct StoreZipMeta |
| 45 | { |
| 46 | uint64_t offset; |
| 47 | uint64_t size; |
| 48 | }; |
| 49 | |
| 50 | std::map<std::string, StoreZipMeta> filemetas; |
| 51 | }; |
| 52 | |
| 53 | class StoreZipWriter |
| 54 | { |
| 55 | public: |
| 56 | StoreZipWriter(); |
| 57 | ~StoreZipWriter(); |
| 58 | |
| 59 | int open(const std::string& path); |
| 60 | |
| 61 | int write_file(const std::string& name, const char* data, uint64_t size); |
| 62 | |
| 63 | int close(); |
| 64 | |
| 65 | private: |
| 66 | FILE* fp; |
| 67 | |
| 68 | struct StoreZipMeta |
| 69 | { |
| 70 | std::string name; |
| 71 | uint64_t lfh_offset; |
| 72 | uint32_t crc32; |
| 73 | uint64_t size; |
| 74 | }; |
| 75 | |
| 76 | std::vector<StoreZipMeta> filemetas; |
| 77 | }; |
| 78 | |
| 79 | } // namespace pnnx |
| 80 | |
| 81 | #endif // PNNX_STOREZIP_H |