Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Copying QFile contents to another QFile, what's the fastest way?

$
0
0
I need to copy a QFile to another QFile in chunks, so I can’t use QFile::copy. Here’s the most primitive implementation: bool CFile::copyChunk(int64_t chunkSize, const QString &destFolder) {     if (!_thisFile.isOpen())     {         // Initializing - opening files         _thisFile.setFileName(_absoluteFilePath);         if (!_thisFile.open(QFile::ReadOnly))             return false;           _destFile.setFileName(destFolder + _thisFileName);         if (!_destFile.open(QFile::WriteOnly))             return false;     }       if (chunkSize < (_thisFile.size() - _thisFile.pos()))     {         QByteArray data (chunkSize, 0);         _thisFile.read(data.data(), chunkSize);         return _destFile.write(data) == chunkSize;     } } It’s not clear from this fragment, but I only intend to copy a binary file as a whole into another location, just in chunks so I can provide progress callbacks and cancellation facility for large files. Another idea is to use memory mapping. Should I? If so, then should I only map source file and still use _destFile.write, or should I map both and use memcpy?

Viewing all articles
Browse latest Browse all 13965

Latest Images

Trending Articles



Latest Images