1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package downloader
- import (
- "fmt"
- "git.bvbej.com/bvbej/base-golang/pkg/downloader/base"
- "git.bvbej.com/bvbej/base-golang/pkg/downloader/controller"
- "git.bvbej.com/bvbej/base-golang/tool"
- "golang.org/x/net/proxy"
- "runtime"
- "testing"
- "time"
- )
- func TestNewDownloader(t *testing.T) {
- dialer, err := proxy.SOCKS5("tcp", "127.0.0.1:1080", nil, proxy.Direct)
- if err != nil {
- t.Fatal(err, dialer)
- }
- err = <-New(
- controller.WithDialer(dialer),
- controller.WithCookie(nil),
- controller.WithTimeout(time.Second*3),
- ).URL("http://10.0.1.34/com.tencent.tmgp.jxqy.apk").
- Listener(func(event *Event) {
- if event.Key == EventKeyFinally {
- fmt.Println("下载完成!")
- }
- if event.Key == EventKeyProgress {
- fmt.Printf("下载速度:%s/s 已下载:%s 已用时:%s \n",
- tool.ByteFmt(event.Task.Progress.Speed),
- tool.ByteFmt(event.Task.Progress.Downloaded),
- time.Duration(event.Task.Progress.Used),
- )
- }
- }).
- Create(&base.Options{
- Connections: runtime.NumCPU(),
- })
- t.Log(err)
- }
|