Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33-pai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
szh
chain33-pai
Commits
e81cb9d5
Commit
e81cb9d5
authored
Dec 19, 2019
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
6251eb0b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
4 deletions
+39
-4
process.go
pkg/app/process.go
+39
-4
No files found.
pkg/app/process.go
View file @
e81cb9d5
...
@@ -264,11 +264,15 @@ func (r *Reader) Read(p []byte) (n int,err error) {
...
@@ -264,11 +264,15 @@ func (r *Reader) Read(p []byte) (n int,err error) {
}
}
func
DownLoadFile
(
url
string
,
file
string
)
error
{
func
DownLoadFile
(
url
string
,
file
string
)
error
{
var
(
buf
=
make
([]
byte
,
32
*
1024
)
)
r
,
err
:=
http
.
Get
(
url
)
r
,
err
:=
http
.
Get
(
url
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
defer
func
()
{
defer
func
()
{
DPercent
.
Current
=
r
.
ContentLength
r
.
Body
.
Close
()
r
.
Body
.
Close
()
}()
}()
...
@@ -280,10 +284,40 @@ func DownLoadFile(url string,file string) error {
...
@@ -280,10 +284,40 @@ func DownLoadFile(url string,file string) error {
f
.
Close
()
f
.
Close
()
}()
}()
DPercent
.
Total
=
r
.
ContentLength
DPercent
.
Total
=
r
.
ContentLength
reader
:=
&
Reader
{
//reader := &Reader{
Reader
:
r
.
Body
,
// Reader:r.Body,
Total
:
r
.
ContentLength
,
// Total:r.ContentLength,
//}
//io.Copy(f,reader)
for
{
//读取bytes
nr
,
er
:=
r
.
Body
.
Read
(
buf
)
if
nr
>
0
{
//写入bytes
nw
,
ew
:=
f
.
Write
(
buf
[
0
:
nr
])
//数据长度大于0
if
nw
>
0
{
DPercent
.
Current
+=
int64
(
nw
)
}
//写入出错
if
ew
!=
nil
{
err
=
ew
break
}
//读取是数据长度不等于写入的数据长度
if
nr
!=
nw
{
err
=
io
.
ErrShortWrite
break
}
}
}
io
.
Copy
(
f
,
reader
)
if
er
!=
nil
{
if
er
!=
io
.
EOF
{
err
=
er
}
break
}
//没有错误了快使用 callback
}
return
nil
return
nil
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment