- if _, err = io.CopyN(tmp.W, bufio.NewReader(fd), fiInt.Size()); err != nil {
- ctx.LogE("nncp-xfer", nncp.SdsAdd(sds, nncp.SDS{"err": err}), "copy")
+ r, w := io.Pipe()
+ go func() {
+ _, err := io.CopyN(w, bufio.NewReader(fd), fiInt.Size())
+ if err == nil {
+ w.Close()
+ return
+ }
+ ctx.LogE("nncp-xfer", sds, err, "copy")
+ w.CloseWithError(err)
+ }()
+ if _, err = nncp.CopyProgressed(tmp.W, r, nncp.SdsAdd(sds, nncp.SDS{
+ "pkt": filename,
+ "fullsize": sds["size"],
+ }), ctx.ShowPrgrs); err != nil {
+ ctx.LogE("nncp-xfer", sds, err, "copy")