Adicionar src-py/renatoxsr/utils/hash_b58.py

This commit is contained in:
2026-09-26 13:19:19 -03:00
parent a8a371861d
commit c14c62b297
+23
View File
@@ -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 <renatoxsr@gmail.com>
# 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)