diff --git a/src-py/renatoxsr/utils/hash_b58.py b/src-py/renatoxsr/utils/hash_b58.py new file mode 100644 index 0000000..cb7029a --- /dev/null +++ b/src-py/renatoxsr/utils/hash_b58.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# vim: set ft=python ts=4 sw=4 et fenc=utf-8 : +# SPDX-FileCopyrightText: 2025-present RenatoXSR +# SPDX-License-Identifier: BSD-3-Clause-Clear +# vim: ts=4 tw=4 sw=4 et: +import base58 +import os, sys, hashlib +from pathlib import Path + +def hash_b58(src_arg: str | Path, hash_algo="sha256", output_print=True, output_stream=sys.stdout): + src = Path(src_arg) + with open(src, "rb") as f: + hash = hashlib.file_digest(f, hash_algo) + hash_hex = hash.hexdigest() + hash_b58 = base58.b58encode(hash.digest()).decode("utf-8") + if output_print: + output_stream.write(f"{hash_algo}:{hash_hex} {hash_b58} '{filename}'\n") + + +def hash_recursive_b58(folder: str | Path, glob="*"): + src = Path(folder) + for filename in src.glob(glob): + hash_b58(filename) \ No newline at end of file