MCPcopy Create free account
hub / github.com/coder/envbuilder / ProgressWriter

Function ProgressWriter

git/git.go:393–421  ·  view source on GitHub ↗
(write func(line string, args ...any))

Source from the content-addressed store, hash-verified

391}
392
393func ProgressWriter(write func(line string, args ...any)) io.WriteCloser {
394 reader, writer := io.Pipe()
395 done := make(chan struct{})
396 go func() {
397 defer close(done)
398 data := make([]byte, 4096)
399 for {
400 read, err := reader.Read(data)
401 if err != nil {
402 return
403 }
404 content := data[:read]
405 for _, line := range strings.Split(string(content), "\r") {
406 if line == "" {
407 continue
408 }
409 // Escape % signs so that they don't get interpreted as format specifiers
410 line = strings.Replace(line, "%", "%%", -1)
411 write(strings.TrimSpace(line))
412 }
413 }
414 }()
415
416 return &progressWriter{
417 WriteCloser: writer,
418 r: reader,
419 done: done,
420 }
421}

Callers 2

runFunction · 0.92
RunCacheProbeFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected