Skip to content

Commit 22f8939

Browse files
committed
fix: flollow the comments when pipe stdin use buffer
Signed-off-by: yihong0618 <[email protected]>
1 parent 16e302c commit 22f8939

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Lib/base64.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,17 @@ def main():
601601
with open(args[0], 'rb') as f:
602602
func(f, sys.stdout.buffer)
603603
else:
604-
# Read all input data at once when reading from stdin
605-
# This allows proper handling of EOF (Ctrl+D)
606-
input_data = sys.stdin.buffer.read()
607-
if input_data:
608-
import io
609-
input_buffer = io.BytesIO(input_data)
610-
func(input_buffer, sys.stdout.buffer)
604+
if sys.stdin.isatty():
605+
# gh-gh-138775: read input data at once when reading from stdin
606+
# This allows proper handling of EOF (Ctrl+D)
607+
input_data = sys.stdin.buffer.read()
608+
if input_data:
609+
import io
610+
input_buffer = io.BytesIO(input_data)
611+
func(input_buffer, sys.stdout.buffer)
612+
else:
613+
# keep the old behaviour for non-interactive input
614+
func(sys.stdin.buffer, sys.stdout.buffer)
611615

612616

613617
if __name__ == '__main__':

0 commit comments

Comments
 (0)