Skip to content

Instantly share code, notes, and snippets.

@K-atc
Created November 22, 2016 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save K-atc/cfc9ec1d38bc011e1e18c2571539a19e to your computer and use it in GitHub Desktop.
Save K-atc/cfc9ec1d38bc011e1e18c2571539a19e to your computer and use it in GitHub Desktop.
binrev - バイナリファイルを逆順に標準出力してくれるpythonスクリプト
#!/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