Skip to content

Commit

Permalink
buffer and fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jehiah committed Feb 18, 2015
1 parent 12a0f28 commit 7a468a9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sample/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
}

0 comments on commit 7a468a9

Please sign in to comment.