11package main
22
33import (
4+ "bufio"
45 "fmt"
5- "io/ioutil"
66 "os"
77
88 "github.com/go-playground/ksql"
9+ "github.com/go-playground/pkg/v5/bytes"
910)
1011
1112func main () {
@@ -25,21 +26,35 @@ func main() {
2526 var input []byte
2627
2728 if isPipe {
28- input , err = ioutil .ReadAll (os .Stdin )
29+ w := bufio .NewWriter (os .Stdout )
30+ scanner := bufio .NewScanner (os .Stdin )
31+ scanner .Buffer (make ([]byte , 0 , 200 * bytesext .KiB ), 5 * bytesext .MiB )
32+ for scanner .Scan () {
33+ result , err := ex .Calculate (scanner .Bytes ())
34+ if err != nil {
35+ fmt .Fprintln (os .Stderr , "reading standard input:" , err )
36+ return
37+ }
38+ if _ , err = fmt .Fprintln (w , result ); err != nil {
39+ fmt .Fprintln (os .Stderr , "writing standard output:" , err )
40+ return
41+ }
42+ }
43+ if err := scanner .Err (); err != nil {
44+ fmt .Fprintln (os .Stderr , "reading standard input:" , err )
45+ }
46+ if err = w .Flush (); err != nil {
47+ fmt .Fprintln (os .Stderr , "writing standard output:" , err )
48+ }
49+ } else {
50+ input = []byte (args [1 ])
51+ result , err := ex .Calculate (input )
2952 if err != nil {
3053 usage ()
3154 return
3255 }
33- } else {
34- input = []byte (args [1 ])
35- }
36-
37- result , err := ex .Calculate (input )
38- if err != nil {
39- usage ()
40- return
56+ fmt .Println (result )
4157 }
42- fmt .Println (result )
4358}
4459
4560func usage () {
0 commit comments