From a7d649871c1ac5174cdd81da98f2bbb55bbef0ac Mon Sep 17 00:00:00 2001 From: PyYoshi Date: Mon, 15 May 2017 09:51:37 +0900 Subject: [PATCH] support stdin --- bin/cchardetect | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/cchardetect b/bin/cchardetect index a71da0e..e51a024 100755 --- a/bin/cchardetect +++ b/bin/cchardetect @@ -1,9 +1,12 @@ #!/usr/bin/env python from __future__ import print_function, unicode_literals import argparse +import sys import cchardet +PY2 = sys.version_info.major == 2 + def read_chunks(f, chunk_size): chunk = f.read(chunk_size) while chunk: @@ -13,7 +16,7 @@ def read_chunks(f, chunk_size): def main(): parser = argparse.ArgumentParser() - parser.add_argument('files', nargs='+', help="Files to detect encoding of", type=argparse.FileType('rb')) + parser.add_argument('files', nargs='*', help="Files to detect encoding of", type=argparse.FileType('rb'), default=[sys.stdin if PY2 else sys.stdin.buffer]) parser.add_argument('--chunk-size', type=int, default=(256 * 1024)) args = parser.parse_args()