1 /* 2 * Copyright (C) 2024 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 #ifndef HDC_ENTRY_H 16 #define HDC_ENTRY_H 17 18 #include <vector> 19 20 #include "header.h" 21 22 namespace Hdc { 23 class Entry { 24 public: 25 Entry(std::string prefix, std::string path); 26 Entry(uint8_t data[512], int dataLen); ~Entry()27 ~Entry() {} 28 IsFinish()29 bool IsFinish() 30 { 31 return this->needSize == 0; 32 } 33 IsInvalid()34 bool IsInvalid() 35 { 36 return this->header.IsInvalid(); 37 } 38 39 void AddData(uint8_t *data, size_t len); Size()40 uint64_t Size() 41 { 42 return header.Size(); 43 } 44 45 bool CopyPayload(std::string prefixPath, std::ifstream &inFile); 46 bool PayloadToFile(std::string prefixPath, std::ifstream &inFile); 47 bool PayloadToDir(std::string prefixPath, std::ifstream &inFile); 48 bool ReadAndWriteData(std::ifstream &inFile, std::ofstream &outFile, uint8_t *buffAppend, 49 int readSize, int writeSize); 50 bool WriteToTar(std::ofstream &file); 51 52 std::string GetName(); 53 bool UpdataName(std::string name); 54 55 private: 56 Header header; 57 uint64_t needSize; 58 std::string prefix; 59 std::vector<uint8_t> data; 60 }; 61 62 } 63 #endif 64