@@ -13,12 +13,12 @@ import (
13
13
"math"
14
14
"net/http"
15
15
"os"
16
+ "path/filepath"
16
17
"strconv"
17
18
"time"
18
- "path/filepath"
19
19
)
20
20
21
- const VERSION = "1.0.2 "
21
+ const VERSION = "1.0.3 "
22
22
23
23
var queue , redo , finish chan int
24
24
var cor , size , length , timeout int
@@ -64,8 +64,8 @@ func main() {
64
64
return
65
65
}
66
66
67
- if dst == "" {
68
- _ ,dst = filepath .Split (url )
67
+ if dst == "" {
68
+ _ , dst = filepath .Split (url )
69
69
}
70
70
71
71
startTime := time .Now ()
@@ -116,7 +116,7 @@ func main() {
116
116
defer file .Close ()
117
117
var offset int64 = 0
118
118
for x := 0 ; x < fragment ; x ++ {
119
- filename := fmt .Sprintf ("tmp_%d" , x )
119
+ filename := fmt .Sprintf ("%s_%d" , dst , x )
120
120
buf , err := ioutil .ReadFile (filename )
121
121
if err != nil {
122
122
log .Println (err )
@@ -141,7 +141,8 @@ func main() {
141
141
}
142
142
143
143
finishTime := time .Now ()
144
- log .Printf ("Time:%f\n " , finishTime .Sub (startTime ).Seconds ())
144
+ duration := finishTime .Sub (startTime ).Seconds ()
145
+ log .Printf ("Time:%f Speed:%f Kb/s\n " , duration , float64 (length )/ duration / 1024 )
145
146
}
146
147
147
148
func Do (request * http.Request , fragment , no int ) {
@@ -153,6 +154,8 @@ func Do(request *http.Request, fragment, no int) {
153
154
return
154
155
}
155
156
for {
157
+ cStartTime := time .Now ()
158
+
156
159
i := <- queue
157
160
//log.Printf("[%d][%d]Start download\n",no, i)
158
161
start := i * size
@@ -163,13 +166,13 @@ func Do(request *http.Request, fragment, no int) {
163
166
end = length - 1
164
167
}
165
168
166
- filename := fmt .Sprintf ("tmp_%d" , i )
169
+ filename := fmt .Sprintf ("%s_%d" , dst , i )
167
170
if cache {
168
- filesize := int64 (end - start + 1 )
171
+ filesize := int64 (end - start + 1 )
169
172
file , err := os .Stat (filename )
170
- if err == nil && file .Size ()== filesize {
171
- log .Printf ("[%d][%d]Hint cached %s, size:%d\n " , no , i , filename ,filesize )
172
- finish <- i
173
+ if err == nil && file .Size () == filesize {
174
+ log .Printf ("[%d][%d]Hint cached %s, size:%d\n " , no , i , filename , filesize )
175
+ finish <- i
173
176
continue
174
177
}
175
178
}
@@ -206,7 +209,9 @@ func Do(request *http.Request, fragment, no int) {
206
209
redo <- i
207
210
continue
208
211
}
209
- log .Printf ("[%d][%d]Wrote successfully:%d\n " , no , i , n )
212
+ cEndTime := time .Now ()
213
+ duration := cEndTime .Sub (cStartTime ).Seconds ()
214
+ log .Printf ("[%d][%d]Download successfully:%f Kb/s\n " , no , i , float64 (n )/ duration / 1024 )
210
215
211
216
file .Close ()
212
217
resp .Body .Close ()
0 commit comments