blob: d9017ccdac878476b78044929cef391ad142ce84 (
plain) (
blame)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include "archiveinputdevice.h"
ArchiveInputDevice::ArchiveInputDevice(archive *a, archive_entry *e, QObject *parent) : QIODevice(parent)
{
m_archive = a;
m_entry = e;
open(QIODevice::ReadOnly);
m_buffer.open(QBuffer::ReadWrite);
}
bool ArchiveInputDevice::seek(qint64 pos)
{
QIODevice::seek(pos);
if(pos > m_buffer.size())
{
char tmp[1024];
qint64 delta = pos - m_buffer.size();
while (delta > 0)
{
qint64 r = qMin(qint64(sizeof(tmp)), delta);
r = archive_read_data(m_archive, tmp, r);
m_buffer.buffer().append(tmp, r);
delta -= r;
}
}
m_buffer.seek(pos);
return true;
}
qint64 ArchiveInputDevice::size() const
{
return archive_entry_size(m_entry);
}
qint64 ArchiveInputDevice::readData(char *data, qint64 maxSize)
{
if(m_buffer.atEnd())
{
char tmp[maxSize];
int r = archive_read_data(m_archive, tmp, maxSize);
m_buffer.buffer().append(tmp, r);
}
return m_buffer.read(data, maxSize);
}
qint64 ArchiveInputDevice::writeData(const char *, qint64)
{
return -1;
}
|