-
Notifications
You must be signed in to change notification settings - Fork 27
/
progress.go
45 lines (39 loc) · 922 Bytes
/
progress.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* knoxite
* Copyright (c) 2016-2017, Christian Muehlhaeuser <muesli@gmail.com>
*
* For license see LICENSE
*/
package knoxite
import "time"
// Progress contains stats and current path.
type Progress struct {
Path string
Timer time.Time
CurrentItemStats Stats
TotalStatistics Stats
Error error
}
func newProgress(archive *Archive) Progress {
return Progress{
Path: archive.Path,
Timer: time.Now(),
CurrentItemStats: Stats{
Size: archive.Size,
StorageSize: archive.StorageSize,
},
TotalStatistics: Stats{
Size: archive.Size,
},
Error: nil,
}
}
func newProgressError(err error) Progress {
return Progress{
Error: err,
}
}
// TransferSpeed returns the average transfer speed in bytes per second.
func (p Progress) TransferSpeed() uint64 {
return uint64(float64(p.CurrentItemStats.Transferred) / time.Since(p.Timer).Seconds())
}