qint64 FileSource size return header size data- size footer size qint6

 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
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());
int toread;
toread = max - buf.size();
if (toread>(data->size() - (curPos - header.size()))) toread = data->size() - (curPos - header.size());
buf.append(data->read(toread));
curPos += toread;
}
while ((curPos < size()) && buf.size() < max)
{
buf.append(footer.at(curPos));
curPos++;
}
strcpy(to, buf.data());
qDebug() << buf;
return buf.size();
}
qint64 FileSource::writeData ( const char *, qint64)
{
return -1;
}