forked from Dax89/QHexView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqhexeditdatadevice.cpp
More file actions
37 lines (29 loc) · 897 Bytes
/
qhexeditdatadevice.cpp
File metadata and controls
37 lines (29 loc) · 897 Bytes
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
#include "qhexeditdatadevice.h"
QHexEditDataDevice::QHexEditDataDevice(QHexEditData *hexeditdata): QIODevice(hexeditdata), _hexeditdata(hexeditdata)
{
this->_reader = new QHexEditDataReader(hexeditdata, this);
this->_writer = new QHexEditDataWriter(hexeditdata, this);
}
qint64 QHexEditDataDevice::size()
{
return this->_hexeditdata->length();
}
qint64 QHexEditDataDevice::readData(char *data, qint64 maxlen)
{
if(!this->_hexeditdata)
return 0;
QByteArray ba = this->_reader->read(this->pos(), maxlen);
if(!ba.isEmpty())
{
memcpy(data, ba.data(), ba.length());
return ba.length();
}
return -1;
}
qint64 QHexEditDataDevice::writeData(const char *data, qint64 len)
{
if(!this->_hexeditdata)
return 0;
this->_writer->replace(this->pos(), QByteArray::fromRawData(data, len));
return len; /* Append if needed */
}