Created
November 22, 2016 16:59
-
-
Save K-atc/cfc9ec1d38bc011e1e18c2571539a19e to your computer and use it in GitHub Desktop.
binrev - バイナリファイルを逆順に標準出力してくれるpythonスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
from sys import stdin, stdout | |
import argparse | |
DESCRIPTION = "binary reverser v.1,0" | |
STDIN = "-" | |
parser = argparse.ArgumentParser(description=DESCRIPTION) | |
parser.add_argument('File', metavar='File', type=str, nargs="?", | |
default=STDIN, | |
help='file to print reversely') | |
args = parser.parse_args() | |
buf = bytes() | |
if args.File == STDIN: | |
try: | |
buf += bytes(stdin.buffer.read()) | |
except StopIteration: | |
pass | |
else: | |
with open(args.File, "rb") as f: | |
buf = bytes(f.read()) | |
stdout.buffer.write(buf[::-1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment