1/*
2 * Copyright (c) 2024-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
16#ifndef SIGNATRUETOOLS_ZIP_DATA_INPUT_H
17#define SIGNATRUETOOLS_ZIP_DATA_INPUT_H
18
19#include <memory>
20
21#include "byte_buffer.h"
22#include "data_source.h"
23#include "random_access_file_output.h"
24
25namespace OHOS {
26namespace SignatureTools {
27
28class ZipDataInput {
29public:
30    virtual ~ZipDataInput()
31    {
32    }
33
34    /**
35     * Get how many bytes are contained in this data input.
36     *
37     * @return this data input size
38     */
39    virtual int64_t Size() = 0;
40
41    /**
42     * Copy the specified data block into the destination ZipDataOutput
43     *
44     * @param offset offset index at the ZipDataInput
45     * @param size size of the data block
46     * @param buffer the destination ZipDataOutput
47     * @throws IOException when IO error occurred
48     */
49    virtual bool CopyTo(int64_t offset, int size, ByteBuffer& buffer) = 0;
50
51    /**
52     * Create a ByteBuffer which contain the specified data block from this ZipDataInput
53     *
54     * @param offset offset index at the ZipDataInput
55     * @param size size of the data block
56     * @return a ByteBuffer
57     * @throws IOException when IO error occurred
58     */
59    virtual ByteBuffer CreateByteBuffer(int64_t offset, int size) = 0;
60
61    /**
62     * Create a new DataSource whose content is shared by this DataSource
63     *
64     * @param offset offset index at the DataSource
65     * @param size size of the data block
66     * @return new DataSource
67     */
68    virtual DataSource* Slice(int64_t offset, int64_t size) = 0;
69};
70} // namespace SignatureTools
71} // namespace OHOS
72#endif // SIGNATRUETOOLS_ZIP_DATA_INPUT_H