修复http上传下载数据丢失问题

master
兔子 5 years ago
parent fe167d7281
commit 6339e3cdf2

@ -85,10 +85,14 @@ func (this *StarCurl) CurlWithFile(url string, postdata map[string]string, formn
fpdst.Write([]byte(header)) fpdst.Write([]byte(header))
go func() { go func() {
for { for {
bufs := make([]byte, 1048576) bufs := make([]byte, 393213)
n, err = fpsrc.Read(bufs) n, err = fpsrc.Read(bufs)
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
if n != 0 {
fpdst.Write(bufs[0:n])
go shell(float64(sum+n) / filebig * 100)
}
break break
} }
return return
@ -99,7 +103,6 @@ func (this *StarCurl) CurlWithFile(url string, postdata map[string]string, formn
} }
fpdst.Write(endbytes) fpdst.Write(endbytes)
fpdst.Write(nil) fpdst.Write(nil)
}() }()
this.CircleBuffer = fpdst this.CircleBuffer = fpdst
this.ReqHeader.Set("Content-Type", "multipart/form-data;boundary="+boundary) this.ReqHeader.Set("Content-Type", "multipart/form-data;boundary="+boundary)
@ -134,10 +137,14 @@ func (this *StarCurl) CurlWithFileByMemory(url string, postdata map[string]strin
filebig := float64(fpstat.Size()) filebig := float64(fpstat.Size())
sum, n := 0, 0 sum, n := 0, 0
for { for {
bufs := make([]byte, 1048576) bufs := make([]byte, 393213)
n, err = fpsrc.Read(bufs) n, err = fpsrc.Read(bufs)
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
if n != 0 {
fpdst.Write(bufs[0:n])
go shell(float64(sum+n) / filebig * 100)
}
break break
} }
return return
@ -231,11 +238,14 @@ func (this *StarCurl) CurlDataToFile(url string, postdata []byte, method, fpath
} }
var n, sum int = 0, 0 var n, sum int = 0, 0
for { for {
buf := make([]byte, 1048576) buf := make([]byte, 393213)
n, err = resp.Body.Read(buf) n, err = resp.Body.Read(buf)
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
err = nil err = nil
if n != 0 {
fpsrc.Write(buf[0:n])
}
go shell(100.00) go shell(100.00)
break break
} }

Loading…
Cancel
Save