Skip to content

Commit b0a4de8

Browse files
committed
buffer and fix formatting
1 parent 354f013 commit b0a4de8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sample/main.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func main() {
2323
os.Exit(1)
2424
}
2525

26+
out := bufio.NewWriterSize(os.Stdout, 1024*512)
27+
2628
rand.Seed(time.Now().UnixNano())
2729
scanner := bufio.NewScanner(os.Stdin)
2830
for scanner.Scan() {
@@ -31,12 +33,13 @@ func main() {
3133
continue
3234
}
3335
emitted += 1
34-
fmt.Printf("%q", scanner.Text()) // Println will add back the final '\n'
36+
out.WriteString(scanner.Text())
37+
out.WriteString("\n")
3538
}
3639
if err := scanner.Err(); err != nil {
3740
fmt.Fprintln(os.Stderr, "Error reading standard input:", err)
3841
os.Exit(2)
3942
}
40-
43+
out.Flush()
4144
fmt.Fprintf(os.Stderr, "Total of %d lines. Sampled to %d\n", total, emitted)
4245
}

0 commit comments

Comments
 (0)