multi-threaded hasher.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "hasher.hpp"
|
#include "hasher.hpp"
|
||||||
#include "app.hpp"
|
#include "app.hpp"
|
||||||
|
#include "threaded_file_transfer.hpp"
|
||||||
#include <mbedtls/md5.h>
|
#include <mbedtls/md5.h>
|
||||||
|
|
||||||
namespace sphaira::hash {
|
namespace sphaira::hash {
|
||||||
@@ -136,22 +137,18 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Result Hash(ui::ProgressBox* pbox, std::unique_ptr<HashSource> hash, std::shared_ptr<BaseSource> source, std::string& out) {
|
Result Hash(ui::ProgressBox* pbox, std::unique_ptr<HashSource> hash, std::shared_ptr<BaseSource> source, std::string& out) {
|
||||||
s64 size;
|
s64 file_size;
|
||||||
R_TRY(source->Size(&size));
|
R_TRY(source->Size(&file_size));
|
||||||
|
|
||||||
s64 offset{};
|
R_TRY(thread::Transfer(pbox, file_size,
|
||||||
std::vector<u8> chunk(1024 * 512);
|
[&](void* data, s64 off, s64 size, u64* bytes_read) -> Result {
|
||||||
while (offset < size) {
|
return source->Read(data, off, size, bytes_read);
|
||||||
R_TRY(pbox->ShouldExitResult());
|
},
|
||||||
const auto rsize = std::min<s64>(chunk.size(), size - offset);
|
[&](const void* data, s64 off, s64 size) -> Result {
|
||||||
|
hash->Update(data, size);
|
||||||
u64 bytes_read;
|
R_SUCCEED();
|
||||||
R_TRY(source->Read(chunk.data(), offset, rsize, &bytes_read));
|
}
|
||||||
hash->Update(chunk.data(), bytes_read);
|
));
|
||||||
|
|
||||||
offset += bytes_read;
|
|
||||||
pbox->UpdateTransfer(offset, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
hash->Get(out);
|
hash->Get(out);
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
|
|||||||
Reference in New Issue
Block a user