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 ZIP_ADAPTER_H 17 #define ZIP_ADAPTER_H 18 #include <iostream> 19 #include <vector> 20 #include "deflate_adapter.h" 21 #include "diffpatch.h" 22 #include "pkg_manager.h" 23 #include "securec.h" 24 #include "zlib.h" 25 26 namespace UpdatePatch { 27 class ZipAdapter : public DeflateAdapter { 28 public: 29 ZipAdapter(UpdatePatchWriterPtr outStream, size_t offset, const Hpackage::PkgManager::FileInfoPtr fileInfo); ~ZipAdapter()30 ~ZipAdapter() override {} 31 32 int32_t Open() override; 33 int32_t Close() override; 34 35 int32_t WriteData(const BlockBuffer &srcData) override; 36 int32_t FlushData(size_t &offset) override; 37 private: 38 std::vector<uint8_t> buffer_ {}; 39 UpdatePatchWriterPtr outStream_; 40 z_stream zstream_ {0}; 41 size_t offset_; 42 43 int32_t level_ {0}; 44 int32_t method_ {0}; 45 int32_t windowBits_ {0}; 46 int32_t memLevel_ {0}; 47 int32_t strategy_ {0}; 48 }; 49 } // namespace UpdatePatch 50 #endif // ZIP_ADAPTER_H 51