/src/karchive/src/klimitediodevice_p.h
Line | Count | Source |
1 | | /* This file is part of the KDE libraries |
2 | | SPDX-FileCopyrightText: 2001, 2002, 2007 David Faure <faure@kde.org> |
3 | | |
4 | | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | | */ |
6 | | |
7 | | #ifndef klimitediodevice_p_h |
8 | | #define klimitediodevice_p_h |
9 | | |
10 | | #include <QDebug> |
11 | | #include <QIODevice> |
12 | | /*! |
13 | | * A readonly device that reads from an underlying device |
14 | | * from a given point to another (e.g. to give access to a single |
15 | | * file inside an archive). |
16 | | * @author David Faure <faure@kde.org> |
17 | | * \internal - used by KArchive |
18 | | */ |
19 | | class KLimitedIODevice : public QIODevice |
20 | | { |
21 | 0 | Q_OBJECT |
22 | 0 | public: |
23 | 0 | /*! |
24 | 0 | * Creates a new KLimitedIODevice. |
25 | 0 | * \a dev the underlying device, opened or not |
26 | 0 | * This device itself auto-opens (in readonly mode), no need to open it. |
27 | 0 | * \a start where to start reading (position in bytes) |
28 | 0 | * \a length the length of the data to read (in bytes) |
29 | 0 | */ |
30 | 0 | KLimitedIODevice(QIODevice *dev, qint64 start, qint64 length); |
31 | 0 | ~KLimitedIODevice() override |
32 | 0 | { |
33 | 0 | } |
34 | | |
35 | | bool isSequential() const override; |
36 | | |
37 | | [[nodiscard]] bool open(QIODevice::OpenMode m) override; |
38 | | void close() override; |
39 | | |
40 | | qint64 size() const override; |
41 | | |
42 | | qint64 readData(char *data, qint64 maxlen) override; |
43 | | qint64 writeData(const char *, qint64) override |
44 | 0 | { |
45 | 0 | return -1; // unsupported |
46 | 0 | } |
47 | | |
48 | | // virtual qint64 pos() const { return m_dev->pos() - m_start; } |
49 | | bool seek(qint64 pos) override; |
50 | | qint64 bytesAvailable() const override; |
51 | | |
52 | | private: |
53 | | QIODevice *m_dev; |
54 | | const qint64 m_start; |
55 | | const qint64 m_length; |
56 | | }; |
57 | | |
58 | | #endif |