I am writing not a big pre-loader on QT, it divides files into parts and downloads by throwing filename_part_1, filename_part_2 and so on to disk.
What is the fastest and most resource-intensive way to integrate them?
Sketched a simple method of combining parts of files into one resulting file:
bool mergeParts(const QString& resultFileName, const QStringList& partsFileNames) { qint64 totalSize = 0; QStringListIterator it(partsFileNames); while (it.hasNext()) { totalSize += QFile(it.next()).size(); } QFile result(resultFileName); result.resize(totalSize); if (result.open(QFile::WriteOnly)) { it.toFront(); while (it.hasNext()) { QFile part(it.next()); if (part.open(QFile::ReadOnly)) { result.write(part.readAll()); result.flush(); } } } }
It remains for you:
Check how satisfied you are with the processing speed. Maybe it is worth saving on calls of constructors QFile
?
Source: https://ru.stackoverflow.com/questions/555982/
All Articles