include filesource include defines include QHttp include QHttpRequestH

 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "filesource.h"
#include "defines.h"
#include <QHttp>
#include <QHttpRequestHeader>
#include <QDebug>
FileSource::FileSource(QString filename)
{
//creation of footer and header is here
data = new QFile(filename);
data->open(QIODevice::ReadOnly);
curPos = 0;
}
bool FileSource::atEnd ()
{
return curPos == size();
}
qint64 FileSource::pos ()
{
return curPos;
}
qint64 FileSource::size ()
{
return header.size() + data->size() + footer.size();
}
qint64 FileSource::readData(char* to, qint64 max)
{
QByteArray buf;
while ((curPos < header.size()) && buf.size() < max)
{
buf.append(header.at(curPos));
curPos++;
}
while ((curPos < (header.size()+data->size())) && buf.size() < max)
{
data->seek(curPos - header.size());
buf.append(data->read(1));
curPos++;
}
while ((curPos < size()) && buf.size() < max)
{
buf.append(footer.at(curPos));
curPos++;
}
memcpy(to, buf.data(), buf.size());
return buf.size();
}
qint64 FileSource::writeData ( const char *, qint64)
{
return 0;
}
qint64 FileSource::bytesAvailable()
{
return header.size() + data->size() + footer.size() + QIODevice::bytesAvailable() - curPos;
}
bool FileSource::isSequential ()
{
return false;
}