Skip to content

SyncReader creates a reader that syncs its reads to all the provided readers, similar to the `io.MultiWriter `.

License

Notifications You must be signed in to change notification settings

go-libs/syncreader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

syncreader

SyncReader creates a reader that its reads to synchronize with first reader, similar to the io.MultiWriter .

View the docs.

APIs

New(readers ...io.Reader)

First reader is source reader, other readers read to synchronize whith first reader. If first readera retures EOF, other readers also return.

Usage

Reading a file in progress.

import "github.com/go-libs/syncreader"
import "github.com/go-libs/progress"

filename := "syncreader_test.go"
f, err := os.Open(filename)
defer f.Close()
if err != nil {
  log.Fatalln(err)
}

fs, err := os.Stat(filename)
if err != nil {
  log.Fatalln(err)
}

p := progress.New()
p.Total = fs.Size()
p.Progress = func(c, t, e int64) {
  log.Println(c, t, e)
}
b := new(bytes.Buffer)
r := syncreader.New(f, p)
_, err = b.ReadFrom(r)
if err != nil {
  log.Fatalln(err)
}

View the docs.

About

SyncReader creates a reader that syncs its reads to all the provided readers, similar to the `io.MultiWriter `.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages