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
26namespace UpdatePatch {
27class ZipAdapter : public DeflateAdapter {
28public:
29    ZipAdapter(UpdatePatchWriterPtr outStream, size_t offset, const Hpackage::PkgManager::FileInfoPtr fileInfo);
30    ~ZipAdapter() override
31    {
32        Close();
33    }
34
35    int32_t Open() override;
36    int32_t Close() override;
37
38    int32_t WriteData(const BlockBuffer &srcData) override;
39    int32_t FlushData(size_t &offset) override;
40private:
41    std::vector<uint8_t> buffer_ {};
42    UpdatePatchWriterPtr outStream_;
43    z_stream zstream_ {0};
44    size_t offset_;
45
46    int32_t level_ {0};
47    int32_t method_ {0};
48    int32_t windowBits_ {0};
49    int32_t memLevel_ {0};
50    int32_t strategy_ {0};
51};
52} // namespace UpdatePatch
53#endif // ZIP_ADAPTER_H
54