mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
sender is more accurate bar
This commit is contained in:
parent
5e7839a282
commit
67abc97c6a
1 changed files with 14 additions and 7 deletions
|
@ -60,6 +60,8 @@ type Session struct {
|
||||||
// Stats/infos
|
// Stats/infos
|
||||||
readingStats *stats.Stats
|
readingStats *stats.Stats
|
||||||
bar *progressbar.ProgressBar
|
bar *progressbar.ProgressBar
|
||||||
|
fileSize int64
|
||||||
|
firstByte bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new sender session
|
// New creates a new sender session
|
||||||
|
@ -177,13 +179,8 @@ func (s *Session) readFile(pathToFile string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
stat, _ := f.Stat()
|
stat, _ := f.Stat()
|
||||||
s.bar = progressbar.NewOptions64(
|
s.fileSize = stat.Size()
|
||||||
stat.Size(),
|
s.firstByte = true
|
||||||
progressbar.OptionSetRenderBlankState(true),
|
|
||||||
progressbar.OptionSetBytes64(stat.Size()),
|
|
||||||
progressbar.OptionSetWriter(os.Stderr),
|
|
||||||
progressbar.OptionThrottle(1/60*time.Second),
|
|
||||||
)
|
|
||||||
log.Debugf("Starting to read data from '%s'", pathToFile)
|
log.Debugf("Starting to read data from '%s'", pathToFile)
|
||||||
s.readingStats.Start()
|
s.readingStats.Start()
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -248,6 +245,16 @@ func (s *Session) onBufferedAmountLow() func() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.sess.NetworkStats.AddBytes(uint64(cur.n))
|
s.sess.NetworkStats.AddBytes(uint64(cur.n))
|
||||||
|
if s.firstByte {
|
||||||
|
s.firstByte = false
|
||||||
|
s.bar = progressbar.NewOptions64(
|
||||||
|
s.fileSize,
|
||||||
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
|
progressbar.OptionSetBytes64(s.fileSize),
|
||||||
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
|
progressbar.OptionThrottle(1/60*time.Second),
|
||||||
|
)
|
||||||
|
}
|
||||||
s.bar.Add(cur.n)
|
s.bar.Add(cur.n)
|
||||||
s.msgToBeSent = s.msgToBeSent[1:]
|
s.msgToBeSent = s.msgToBeSent[1:]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue