@@ -54,6 +54,8 @@ type runner struct {
54
54
lastErr error
55
55
lastStatusTime int64
56
56
lastBytesUncompressed int64
57
+
58
+ noProgress bool
57
59
}
58
60
59
61
// st renders Status as a string.
@@ -80,13 +82,25 @@ func (r *runner) st(s progress.Status) string {
80
82
if len (r .sizes ) > 1 && r .parallel <= 1 {
81
83
pr .CurrentFilePercent = 100 * float64 (r .currentFile .Bytes ()) / float64 (r .currentTotal )
82
84
83
- res = fmt .Sprintf ("all: %.1f%% bytes read, %s: %.1f%% bytes read, %d lines processed, %.1f l/s, %.1f MB/s, elapsed %s, remaining %s" ,
84
- s .DonePercent , s .Task , pr .CurrentFilePercent , s .LinesCompleted , s .SpeedLPS , s .SpeedMBPS ,
85
- s .Elapsed .Round (10 * time .Millisecond ).String (), s .Remaining .String ())
85
+ if s .LinesCompleted != 0 {
86
+ res = fmt .Sprintf ("all: %.1f%% bytes read, %s: %.1f%% bytes read, %d lines processed, %.1f l/s, %.1f MB/s, elapsed %s, remaining %s" ,
87
+ s .DonePercent , s .Task , pr .CurrentFilePercent , s .LinesCompleted , s .SpeedLPS , s .SpeedMBPS ,
88
+ s .Elapsed .Round (10 * time .Millisecond ).String (), s .Remaining .String ())
89
+ } else {
90
+ res = fmt .Sprintf ("all: %.1f%% bytes read, %s: %.1f%% bytes read, %.1f MB/s, elapsed %s, remaining %s" ,
91
+ s .DonePercent , s .Task , pr .CurrentFilePercent , s .SpeedMBPS ,
92
+ s .Elapsed .Round (10 * time .Millisecond ).String (), s .Remaining .String ())
93
+ }
86
94
} else {
87
- res = fmt .Sprintf ("%s: %.1f%% bytes read, %d lines processed, %.1f l/s, %.1f MB/s, elapsed %s, remaining %s" ,
88
- s .Task , s .DonePercent , s .LinesCompleted , s .SpeedLPS , s .SpeedMBPS ,
89
- s .Elapsed .Round (10 * time .Millisecond ).String (), s .Remaining .String ())
95
+ if s .LinesCompleted != 0 {
96
+ res = fmt .Sprintf ("%s: %.1f%% bytes read, %d lines processed, %.1f l/s, %.1f MB/s, elapsed %s, remaining %s" ,
97
+ s .Task , s .DonePercent , s .LinesCompleted , s .SpeedLPS , s .SpeedMBPS ,
98
+ s .Elapsed .Round (10 * time .Millisecond ).String (), s .Remaining .String ())
99
+ } else {
100
+ res = fmt .Sprintf ("%s: %.1f%% bytes read, %.1f MB/s, elapsed %s, remaining %s" ,
101
+ s .Task , s .DonePercent , s .SpeedMBPS ,
102
+ s .Elapsed .Round (10 * time .Millisecond ).String (), s .Remaining .String ())
103
+ }
90
104
}
91
105
92
106
if currentBytesUncompressed > currentBytes {
@@ -125,6 +139,15 @@ func (r *runner) st(s progress.Status) string {
125
139
return res
126
140
}
127
141
142
+ func (r * runner ) readFile (rd io.Reader , out io.Writer ) {
143
+ b := bufio .NewReaderSize (rd , 64 * 1024 )
144
+
145
+ _ , err := io .Copy (out , b )
146
+ if err != nil {
147
+ log .Fatal (err )
148
+ }
149
+ }
150
+
128
151
func (r * runner ) scanFile (rd io.Reader , out io.Writer ) {
129
152
s := bufio .NewScanner (rd )
130
153
s .Buffer (make ([]byte , 64 * 1024 ), 10 * 1024 * 1024 )
@@ -236,30 +259,35 @@ func (r *runner) cat(filename string) (err error) {
236
259
}
237
260
}()
238
261
239
- cr := progress .NewCountingReader (file )
240
- cr .SetBytes (& r .currentBytes )
241
- cr .SetLines (nil )
262
+ rd := io .Reader (file )
242
263
243
- if r .parallel <= 1 {
244
- cr = progress .NewCountingReader (file )
264
+ if ! r .noProgress {
265
+ cr := progress .NewCountingReader (file )
266
+ cr .SetBytes (& r .currentBytes )
245
267
cr .SetLines (nil )
246
- r .currentFile = cr
247
- r .currentTotal = r .sizes [filename ]
248
- }
249
268
250
- rd := io .Reader (cr )
269
+ if r .parallel <= 1 {
270
+ cr = progress .NewCountingReader (file )
271
+ cr .SetLines (nil )
272
+ r .currentFile = cr
273
+ r .currentTotal = r .sizes [filename ]
274
+ }
275
+
276
+ rd = cr
277
+ }
251
278
252
279
if rd , err = r .openReader (rd , filename ); err != nil {
253
280
return err
254
281
}
255
282
256
- crl := progress .NewCountingReader (rd )
283
+ if ! r .noProgress {
284
+ crl := progress .NewCountingReader (rd )
257
285
258
- crl .SetBytes (& r .currentBytesUncompressed )
259
- crl .SetLines (& r .currentLines )
260
- crl .SetLines (nil )
286
+ crl .SetBytes (& r .currentBytesUncompressed )
287
+ crl .SetLines (nil )
261
288
262
- rd = crl
289
+ rd = crl
290
+ }
263
291
264
292
out := r .output
265
293
@@ -285,7 +313,7 @@ func (r *runner) cat(filename string) (err error) {
285
313
out = w
286
314
}
287
315
288
- if r .parallel <= 1 {
316
+ if r .parallel <= 1 && ! r . noProgress {
289
317
r .pr .Start (func (t * progress.Task ) {
290
318
t .TotalBytes = func () int64 {
291
319
return r .totalBytes
@@ -299,9 +327,13 @@ func (r *runner) cat(filename string) (err error) {
299
327
})
300
328
}
301
329
302
- r .scanFile (rd , out )
330
+ if len (r .pass ) > 0 || len (r .skip ) > 0 || r .parallel > 1 {
331
+ r .scanFile (rd , out )
332
+ } else {
333
+ r .readFile (rd , out )
334
+ }
303
335
304
- if r .parallel <= 1 {
336
+ if r .parallel <= 1 && ! r . noProgress {
305
337
r .pr .Stop ()
306
338
}
307
339
@@ -399,7 +431,7 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo,maintidx
399
431
cpuProfile := flag .String ("dbg-cpu-prof" , "" , "write first 10 seconds of CPU profile to file" )
400
432
memProfile := flag .String ("dbg-mem-prof" , "" , "write heap profile to file after 10 seconds" )
401
433
output := flag .String ("output" , "" , "output to file (can have .gz or .zst ext for compression) instead of STDOUT" )
402
- noProgress := flag .Bool ( "no-progress" , false , "disable progress printing" )
434
+ flag .BoolVar ( & r . noProgress , "no-progress" , false , "disable progress printing" )
403
435
progressJSON := flag .String ("progress-json" , "" , "write current progress to a file" )
404
436
ver := flag .Bool ("version" , false , "print version and exit" )
405
437
@@ -523,7 +555,7 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo,maintidx
523
555
Print : func (status progress.Status ) {
524
556
s := r .st (status )
525
557
526
- if * noProgress {
558
+ if r . noProgress {
527
559
return
528
560
}
529
561
@@ -581,6 +613,12 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo,maintidx
581
613
}
582
614
583
615
pr .Stop ()
616
+
617
+ close (errs )
618
+
619
+ if err := <- errs ; err != nil {
620
+ return err
621
+ }
584
622
} else {
585
623
for i := 0 ; i < flag .NArg (); i ++ {
586
624
if err := r .cat (flag .Arg (i )); err != nil {
0 commit comments