/*
NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2020 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
"time"
"github.com/dustin/go-humanize"
- "go.cypherpunks.ru/nncp/v5/uilive"
+ "go.cypherpunks.ru/nncp/v7/uilive"
)
func init() {
dst io.Writer,
src io.Reader,
prgrsPrefix string,
- sds SDS,
+ les LEs,
showPrgrs bool,
) (written int64, err error) {
buf := make([]byte, EncBlkSize)
if nw > 0 {
written += int64(nw)
if showPrgrs {
- sds["size"] = written
- Progress(prgrsPrefix, sds)
+ Progress(prgrsPrefix, append(les, LE{"Size", written}))
}
}
if ew != nil {
return
}
-func Progress(prefix string, sds SDS) {
+func Progress(prefix string, les LEs) {
var size int64
- if sizeI, exists := sds["size"]; exists {
- size = sizeI.(int64)
+ var fullsize int64
+ var pkt string
+ for _, le := range les {
+ switch le.K {
+ case "Size":
+ size = le.V.(int64)
+ case "FullSize":
+ fullsize = le.V.(int64)
+ case "Pkt":
+ pkt = le.V.(string)
+ }
}
- fullsize := sds["fullsize"].(int64)
- pkt := sds["pkt"].(string)
progressBarsLock.RLock()
- pb, exists := progressBars[pkt]
+ pb := progressBars[pkt]
progressBarsLock.RUnlock()
- if !exists {
+ if pb == nil {
progressBarsLock.Lock()
pb = ProgressBarNew(size, fullsize)
progressBars[pkt] = pb
progressBarsLock.Unlock()
}
what := pkt
- if len(what) >= 52 { // Base32 encoded
+ if len(what) >= Base32Encoded32Len { // Base32 encoded
what = what[:16] + ".." + what[len(what)-16:]
}
what = prefix + " " + what
progressBarsLock.Unlock()
}
}
+
+func ProgressKill(pkt string) {
+ progressBarsLock.Lock()
+ pb := progressBars[pkt]
+ if pb != nil {
+ pb.Kill()
+ delete(progressBars, pkt)
+ }
+ progressBarsLock.Unlock()
+}