aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/modelinglib/qmt/infrastructure/qcompressedfile.h
blob: 49a4dc7f2c9884151ce4c50125e53a9074224214 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (C) 2016 Jochen Becher
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include <QIODevice>
#include <QByteArray>

namespace qmt {

class QCompressedDevice : public QIODevice
{
    Q_OBJECT

public:
    explicit QCompressedDevice(QObject *parent = nullptr);
    explicit QCompressedDevice(QIODevice *targetDevice, QObject *parent = nullptr);
    ~QCompressedDevice() override;

    QIODevice *targetDevice() const { return m_targetDevice; }
    void setTargetDevice(QIODevice *targetDevice);

    void close() override;

protected:
    qint64 readData(char *data, qint64 maxlen) override;
    qint64 writeData(const char *data, qint64 len) override;

public:
    qint64 flush();

private:
    QIODevice *m_targetDevice = nullptr;
    QByteArray m_buffer;
    qint64 m_bytesInBuffer = 0;
    qint64 m_indexInBuffer = 0;
};

} // namespace qmt