Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_sha256sum.cpp
Go to the documentation of this file.
4
5#include <iostream>
6#include <iomanip>
7
8/////////////////////////////////////////////////////////////////////////////
9int main(int argc, char **argv)
10/////////////////////////////////////////////////////////////////////////////
11{
12 std::cout << std::hex;
13 std::cout << std::setfill('0');
14
15 joedb::Arguments arguments(argc, argv);
16 const bool fast = arguments.has_flag("fast");
17
18 while (arguments.get_remaining_count())
19 {
20 const std::string_view file_name = arguments.get_next();
21
22 try
23 {
24 joedb::File file(file_name.data(), joedb::Open_Mode::read_existing);
25
26 const joedb::SHA_256::Hash hash = fast ?
27 joedb::File_Hasher::get_fast_hash(file, 0, file.get_size()) :
29
30 for (uint32_t i = 0; i < 8; i++)
31 std::cout << std::setw(8) << hash[i];
32 std::cout << " " << file_name << '\n';
33 }
34 catch (const joedb::Exception &e)
35 {
36 std::cout << file_name << ": Error: " << e.what() << '\n';
37 }
38 }
39
40 return 0;
41}
Class for conveniently parsing command-line arguments.
Definition Arguments.h:19
std::string_view get_next()
int get_remaining_count() const
Definition Arguments.h:122
bool has_flag(const char *name)
Definition Arguments.cpp:36
static SHA_256::Hash get_fast_hash(Buffered_File &file, int64_t start, int64_t size)
static SHA_256::Hash get_hash(Buffered_File &file, int64_t start, int64_t size)
std::array< uint32_t, 8 > Hash
Definition SHA_256.h:60
int main()
@ read_existing
fails if does not exist
JOEDB_FILE File
Definition File.h:25