From 8f72609494aefe837b6ac30e38625b4d7aa21274 Mon Sep 17 00:00:00 2001 From: Jehiah Czebotar Date: Thu, 17 Jul 2014 21:44:58 -0400 Subject: [PATCH] buffer and fix formatting --- sample/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sample/main.go b/sample/main.go index d9f2b68..069c499 100644 --- a/sample/main.go +++ b/sample/main.go @@ -23,6 +23,8 @@ func main() { os.Exit(1) } + out := bufio.NewWriterSize(os.Stdout, 1024*512) + rand.Seed(time.Now().UnixNano()) scanner := bufio.NewScanner(os.Stdin) for scanner.Scan() { @@ -31,12 +33,13 @@ func main() { continue } emitted += 1 - fmt.Printf("%q", scanner.Text()) // Println will add back the final '\n' + out.WriteString(scanner.Text()) + out.WriteString("\n") } if err := scanner.Err(); err != nil { fmt.Fprintln(os.Stderr, "Error reading standard input:", err) os.Exit(2) } - + out.Flush() fmt.Fprintf(os.Stderr, "Total of %d lines. Sampled to %d\n", total, emitted) }