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 */
19class KLimitedIODevice : public QIODevice
20{
21 Q_OBJECT
22public:
23 /**
24 * Creates a new KLimitedIODevice.
25 * @param dev the underlying device, opened or not
26 * This device itself auto-opens (in readonly mode), no need to open it.
27 * @param start where to start reading (position in bytes)
28 * @param length the length of the data to read (in bytes)
29 */
30 KLimitedIODevice(QIODevice *dev, qint64 start, qint64 length);
31 ~KLimitedIODevice() override
32 {
33 }
34
35 bool isSequential() const override;
36
37 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 {
45 return -1; // unsupported
46 }
47
48 // virtual qint64 pos() const { return m_dev->pos() - m_start; }
49 bool seek(qint64 pos) override;
50 qint64 bytesAvailable() const override;
51
52private:
53 QIODevice *m_dev;
54 qint64 m_start;
55 qint64 m_length;
56};
57
58#endif
59

source code of karchive/src/klimitediodevice_p.h