Skip to content

Commit df52bae

Browse files
committed
New --b2sum option as alternative to b2sum binary
Usage: paperbackup.py --b2sum FILE echo "DATA" | paperbackup.py --b2sum Print b2sum of FILE or DATA on stdout and exit. NOTE: does not append the file name.
1 parent 382fcbe commit df52bae

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

paperbackup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ def finish_page(pdf, canv, pageno):
7171

7272
# main code
7373

74+
if sys.argv[1] == "--b2sum":
75+
if len(sys.argv) > 2:
76+
with open(sys.argv[2], 'r') as ifile:
77+
data = ''.join(ifile.readlines())
78+
else:
79+
data = ''.join(sys.stdin.readlines())
80+
print(hashlib.blake2b(bytes(data, 'utf8')).hexdigest())
81+
sys.exit(0)
82+
7483
if len(sys.argv) != 2:
7584
raise RuntimeError('Usage {} FILENAME.asc'.format(sys.argv[0]))
7685

0 commit comments

Comments
 (0)