-
Notifications
You must be signed in to change notification settings - Fork 5
/
asterixFileMapper.cpp
80 lines (62 loc) · 1.64 KB
/
asterixFileMapper.cpp
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
71
72
73
74
75
76
77
78
/*
* This application is free software and is released under the terms of
* the BSD license. See LICENSE file for details.
*
* Copyright (c) 2010 Volker Poplawski ([email protected])
*/
#include "asterixFileMapper.h"
AsterixFileMapper::AsterixFileMapper(QIODevice* file, QObject *parent) :
QThread(parent),
m_file(file),
m_offset(0)
{
m_reachedEnd = false;
qRegisterMetaType<QList<AsterixBlockInfo> >();
}
void AsterixFileMapper::run()
{
qint64 blockCount = 0;
m_stopRequested = false;
m_file->seek(m_offset);
while (m_reachedEnd == false && m_stopRequested == false)
{
QList<AsterixBlockInfo> ret;
QTime time;
time.start();
do {
if (m_file->atEnd())
{
m_reachedEnd = true;
break;
}
m_file->seek(m_offset);
qint64 offset = m_file->pos();
quint8 category;
if (not m_file->read((char*)&category, 1))
break;
char sbuffer[2];
if (not m_file->read(sbuffer, 2))
break;
quint16 blockSize = qFromBigEndian<quint16>((uchar*)sbuffer);
if (blockSize >= 3 // valid blocksize
&& // and
offset + blockSize <= m_file->size() ) // block not truncated?
{
// yes
AsterixBlockInfo block = { offset, category, blockSize };
ret << block;
}
else
{
m_reachedEnd = true;
break;
}
m_offset += blockSize;
blockCount++;
} while (time.elapsed() < 100);
emit asterixBlock(ret);
emit bytesScanned(m_offset);
emit blocksScanned(blockCount);
msleep(50);
}
}