Skip to content

Commit 6f97d80

Browse files
committed
tools/checksum: fix input from stdin
argparse is supposed to take care of this automatically, but it wasn't working due to the fact that argparse ignores the binary specifier for stdin.
1 parent 98cf695 commit 6f97d80

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tools/checksum.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import argparse
1212
import struct
13+
import sys
1314

1415

1516
def sum_complement(fw, max_size):
@@ -133,6 +134,13 @@ def crc32_checksum(fw, max_size):
133134

134135
args = parser.parse_args()
135136

137+
# argparse doesn't know how to handle "rb" for stdin and gives us TextIO
138+
# instead of BinaryIO
139+
if args.fw_file == sys.stdin:
140+
if sys.stdin.isatty():
141+
raise RuntimeError("expecting data to be piped via stdin")
142+
args.fw_file = sys.stdin.buffer
143+
136144
if args.checksum_type == "xor":
137145
print(hex(sum_complement(args.fw_file, args.max_size)))
138146
elif args.checksum_type == "crc32":

0 commit comments

Comments
 (0)