[SOLVED] Overwrite specific bytes without reading the whole file, QFile
-
wrote on 30 Jul 2011, 13:46 last edited by
Hi guys :)
I have been looking for a way to overwrite specific files in a file, but could only find something about memory mapping the file...let me explain :)
let's suppose I want to overwrite byte 0x51B...I use this code
@ QFile cre("C:/stubs/200159ED.cre");
if (!cre.open(QIODevice::WriteOnly)) return -10;
cre.seek(0x51B);
QDataStream crestream(&cre;);
qint8 attempt = 1;
crestream << attempt;
cre.close()@the problem is the file is first erased, and then it's filled with 0s, until 0x51B is reached, which is correctly set to 01...
Is there any way I can avoid erasing the whole file before writing into it?
I'd also like to avoid reading the whole file, changing some bits, and then writing it back to a new file, because the file could be pretty big :)
Thanks in advance :)
faenil
-
wrote on 30 Jul 2011, 14:15 last edited by
Yep. WriteOnly will silently truncate. Open the file with ReadWrite.
cf. https://qt.gitorious.org/qt/qt/blobs/master/src/corelib/io/qfsfileengine.cpp#line201
-
wrote on 30 Jul 2011, 14:17 last edited by
thank you very much :) and thanks for the precious link :)
-
wrote on 30 Jul 2011, 21:04 last edited by
If your initial question is answered and you consider the issue solved, please edit your initial post to change the title from
Overwrite specific bytes without reading the whole file, QFile
to
[SOLVED] Overwrite specific bytes without reading the whole file, QFile
-
wrote on 30 Jul 2011, 21:06 last edited by
I'll try it tomorrow morning and check if it's solved ;) thanks for the tip anyway ;)
-
wrote on 30 Jul 2011, 21:08 last edited by
[quote author="faenil" date="1312059979"]I'll try it tomorrow morning and check if it's solved ;) thanks for the tip anyway ;) [/quote]
Even better! :-)
2/6