The ctxio
package gives golang io.copy
operations the ability to terminate with context and retrieve progress data.
go get github.com/binalyze/ctxio
Here is an example to use ctxio
with io.copy
operation. You can find more examples in test files.
srcFile, err := os.Open("sourcefile.log")
dstFile, err := os.Create("destinationFile.log")
progressFn := func(n int64) {
// Here you can send progress to API etc.
}
w := NewWriter(ctx, dstFile, progressFn)
written, err := io.Copy(w, file)
- Add io.Reader support just like io.Writer
- context-aware-ioreader-for-golang-by-mat-ryer Context-aware io.Reader for Go.
- github.com/jbenet/go-context/io Context-aware reader and writer.
- github.com/northbright/ctx/ctxcopy Context-aware io.Copy.
- gitlab.com/streamy/concon Context-aware net.Conn.