1
0
mirror of https://github.com/fumiama/RVC-Models-Downloader.git synced 2024-11-17 13:47:11 +09:00
RVC-Models-Downloader/log.go
2024-04-19 00:29:30 +09:00

43 lines
736 B
Go

package main
import (
"errors"
"io"
"github.com/sirupsen/logrus"
)
var (
errZeroMeterSize = errors.New("zero meter size")
)
type progressmeter struct {
prefix string
name string
size int
prgs int
lstp int
io.Writer
}
func newmeter(prefix, name string, size int) (pm progressmeter) {
pm.prefix = prefix
pm.name = name
pm.size = size
return
}
func (pm *progressmeter) Write(p []byte) (n int, err error) {
if pm.size == 0 {
return 0, errZeroMeterSize
}
pm.prgs += len(p)
percent := pm.prgs * 100 / pm.size
if percent == pm.lstp {
return len(p), nil
}
logrus.Infof("%s [%2d%%] %s\t(%d/%dMB)", pm.prefix, percent, pm.name, pm.prgs/1024/1024, pm.size/1024/1024)
pm.lstp = percent
return len(p), nil
}