File: example.py

package info (click to toggle)
blake3-py 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,036 kB
  • sloc: asm: 17,520; ansic: 4,109; python: 587; makefile: 15
file content (23 lines) | stat: -rwxr-xr-x 501 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#! /usr/bin/env python3

import sys

from blake3 import blake3

# Open the input file, if a command line argument is provided. Otherwise read
# from stdin.
if len(sys.argv) > 1:
    assert len(sys.argv) == 2
    input_file = open(sys.argv[1], "rb")
else:
    input_file = sys.stdin.buffer

# Hash stdin in 64 KiB chunks.
hasher = blake3()
buf = memoryview(bytearray(65536))
while True:
    n = input_file.readinto(buf)
    if n == 0:
        break
    hasher.update(buf[:n])
print(hasher.hexdigest())