mirror of https://github.com/schollz/croc.git
add progressbar
This commit is contained in:
parent
e2dde7d46f
commit
cdc962b59a
1
go.mod
1
go.mod
|
@ -10,6 +10,7 @@ require (
|
||||||
github.com/pkg/errors v0.8.1
|
github.com/pkg/errors v0.8.1
|
||||||
github.com/schollz/logger v1.0.1
|
github.com/schollz/logger v1.0.1
|
||||||
github.com/schollz/pake/v2 v2.0.3-0.20191113001949-efbd97a5fff1
|
github.com/schollz/pake/v2 v2.0.3-0.20191113001949-efbd97a5fff1
|
||||||
|
github.com/schollz/progressbar/v2 v2.14.0
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/tscholl2/siec v0.0.0-20191103131401-2e0c53a9e212 // indirect
|
github.com/tscholl2/siec v0.0.0-20191103131401-2e0c53a9e212 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708
|
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708
|
||||||
|
|
5
go.sum
5
go.sum
|
@ -31,6 +31,8 @@ github.com/marten-seemann/qtls v0.2.3 h1:0yWJ43C62LsZt08vuQJDK1uC1czUc3FJeCLPoNA
|
||||||
github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
|
github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
|
||||||
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
|
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
|
||||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||||
|
@ -84,6 +86,9 @@ github.com/schollz/pake/v2 v2.0.2 h1:p9y4Gocc5PWueyhhR7OH+Gwpu2xkP5BM9Pepl9krVfo
|
||||||
github.com/schollz/pake/v2 v2.0.2/go.mod h1:3uXB571UYJ8Eqh2EEohXe/aO32QID+Varb4GeYA//yw=
|
github.com/schollz/pake/v2 v2.0.2/go.mod h1:3uXB571UYJ8Eqh2EEohXe/aO32QID+Varb4GeYA//yw=
|
||||||
github.com/schollz/pake/v2 v2.0.3-0.20191113001949-efbd97a5fff1 h1:1WpHD2WEsvFNag5ufk1zWv+NkgYbU4QeMS5rFXJI5dk=
|
github.com/schollz/pake/v2 v2.0.3-0.20191113001949-efbd97a5fff1 h1:1WpHD2WEsvFNag5ufk1zWv+NkgYbU4QeMS5rFXJI5dk=
|
||||||
github.com/schollz/pake/v2 v2.0.3-0.20191113001949-efbd97a5fff1/go.mod h1:3uXB571UYJ8Eqh2EEohXe/aO32QID+Varb4GeYA//yw=
|
github.com/schollz/pake/v2 v2.0.3-0.20191113001949-efbd97a5fff1/go.mod h1:3uXB571UYJ8Eqh2EEohXe/aO32QID+Varb4GeYA//yw=
|
||||||
|
github.com/schollz/progressbar v1.0.0 h1:gbyFReLHDkZo8mxy/dLWMr+Mpb1MokGJ1FqCiqacjZM=
|
||||||
|
github.com/schollz/progressbar/v2 v2.14.0 h1:vo7bdkI9E4/CIk9DnL5uVIaybLQiVtiCC2vO+u9j5IM=
|
||||||
|
github.com/schollz/progressbar/v2 v2.14.0/go.mod h1:6YZjqdthH6SCZKv2rqGryrxPtfmRB/DWZxSMfCXPyD8=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/schollz/croc/v7/src/models"
|
"github.com/schollz/croc/v7/src/models"
|
||||||
log "github.com/schollz/logger"
|
log "github.com/schollz/logger"
|
||||||
"github.com/schollz/pake/v2"
|
"github.com/schollz/pake/v2"
|
||||||
|
"github.com/schollz/progressbar/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Debug toggles debug mode
|
// Debug toggles debug mode
|
||||||
|
@ -385,7 +386,7 @@ func (c *Client) CreateOfferer(finished chan<- error) (pc *webrtc.PeerConnection
|
||||||
|
|
||||||
var readyToBegin = false
|
var readyToBegin = false
|
||||||
var readyToEnd = false
|
var readyToEnd = false
|
||||||
|
var bar *progressbar.ProgressBar
|
||||||
dc.OnOpen(func() {
|
dc.OnOpen(func() {
|
||||||
log.Debug("data channel is open")
|
log.Debug("data channel is open")
|
||||||
if c.Options.IsSender {
|
if c.Options.IsSender {
|
||||||
|
@ -402,6 +403,11 @@ func (c *Client) CreateOfferer(finished chan<- error) (pc *webrtc.PeerConnection
|
||||||
log.Debug("transfering file")
|
log.Debug("transfering file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bar = progressbar.NewOptions64(fstat.Size(),
|
||||||
|
progressbar.OptionSetBytes64(fstat.Size()),
|
||||||
|
progressbar.OptionSetPredictTime(true),
|
||||||
|
progressbar.OptionThrottle(100*time.Millisecond),
|
||||||
|
)
|
||||||
timeStart := time.Now()
|
timeStart := time.Now()
|
||||||
for {
|
for {
|
||||||
for {
|
for {
|
||||||
|
@ -412,6 +418,7 @@ func (c *Client) CreateOfferer(finished chan<- error) (pc *webrtc.PeerConnection
|
||||||
}
|
}
|
||||||
data := make([]byte, maxPacketSizeHalf)
|
data := make([]byte, maxPacketSizeHalf)
|
||||||
n, errRead := f.Read(data)
|
n, errRead := f.Read(data)
|
||||||
|
bar.Add(n)
|
||||||
if errRead != nil {
|
if errRead != nil {
|
||||||
if errRead == io.EOF {
|
if errRead == io.EOF {
|
||||||
break
|
break
|
||||||
|
@ -456,6 +463,7 @@ func (c *Client) CreateOfferer(finished chan<- error) (pc *webrtc.PeerConnection
|
||||||
})
|
})
|
||||||
|
|
||||||
var fileSize int64
|
var fileSize int64
|
||||||
|
|
||||||
// Register the OnMessage to handle incoming messages
|
// Register the OnMessage to handle incoming messages
|
||||||
dc.OnMessage(func(dcMsg webrtc.DataChannelMessage) {
|
dc.OnMessage(func(dcMsg webrtc.DataChannelMessage) {
|
||||||
var fd FileData
|
var fd FileData
|
||||||
|
@ -488,6 +496,11 @@ func (c *Client) CreateOfferer(finished chan<- error) (pc *webrtc.PeerConnection
|
||||||
fileSize = 0
|
fileSize = 0
|
||||||
} else {
|
} else {
|
||||||
log.Debugf("receiving file sized %d", fileSize)
|
log.Debugf("receiving file sized %d", fileSize)
|
||||||
|
bar = progressbar.NewOptions64(fileSize,
|
||||||
|
progressbar.OptionSetBytes64(fileSize),
|
||||||
|
progressbar.OptionSetPredictTime(true),
|
||||||
|
progressbar.OptionThrottle(100*time.Millisecond),
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,7 +508,8 @@ func (c *Client) CreateOfferer(finished chan<- error) (pc *webrtc.PeerConnection
|
||||||
err = box.Unbundle(string(dcMsg.Data), c.Key, &fd)
|
err = box.Unbundle(string(dcMsg.Data), c.Key, &fd)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// log.Debug(fd.Position)
|
// log.Debug(fd.Position)
|
||||||
fwrite.Write(fd.Data)
|
n, _ := fwrite.Write(fd.Data)
|
||||||
|
bar.Add(n)
|
||||||
sendData([]byte{2, 3, 4})
|
sendData([]byte{2, 3, 4})
|
||||||
} else {
|
} else {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
|
Loading…
Reference in New Issue