-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.cpp
More file actions
29 lines (26 loc) · 702 Bytes
/
hash.cpp
File metadata and controls
29 lines (26 loc) · 702 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
#include "hash.h"
#include <QCryptographicHash>
#include <QFile>
#include <QByteArray>
QVector<FileHash> Hash::calculateHash(const QVector<QString> & input)
{
QVector<FileHash> result;
for(auto i : input)
{
result.push_back(FileHash(i, hash1MBFile(i)));
}
return result;
}
QString Hash::hash1MBFile(const QString & filePath){
QString result;
QFile file(filePath);
int size = 1024 * 1024;
if(file.open(QIODevice::ReadOnly) == true)
{
QByteArray fileData = file.read(size);
QByteArray hashData = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
result = hashData.toHex();
}
file.close();
return result;
}