Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
7f6e96f4
Commit
7f6e96f4
authored
Nov 16, 2018
by
Cristian Maglie
Committed by
Cristian Maglie
Nov 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated go.bug.st/downloader
Fix #87
parent
a32d52fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
12 deletions
+18
-12
Gopkg.lock
Gopkg.lock
+2
-2
vendor/go.bug.st/downloader/downloader.go
vendor/go.bug.st/downloader/downloader.go
+16
-10
No files found.
Gopkg.lock
View file @
7f6e96f4
...
@@ -397,11 +397,11 @@
...
@@ -397,11 +397,11 @@
[[projects]]
[[projects]]
branch = "master"
branch = "master"
digest = "1:
5cd3c0f530ab660c7b08f563020dc00b8e761c2f7650457a3f669b6601f7f28d
"
digest = "1:
975e88bfd9ed90a0e939a9e67ecab0682a28c0b9ed021bd30f469a0b5b4e3739
"
name = "go.bug.st/downloader"
name = "go.bug.st/downloader"
packages = ["."]
packages = ["."]
pruneopts = "UT"
pruneopts = "UT"
revision = "
60d736642c5c2252f6d19016d7e68178b19478f
0"
revision = "
9b8976a44d87b5d86444bccc3ed875b2530f45e
0"
[[projects]]
[[projects]]
branch = "master"
branch = "master"
...
...
vendor/go.bug.st/downloader/downloader.go
View file @
7f6e96f4
...
@@ -11,19 +11,20 @@ import (
...
@@ -11,19 +11,20 @@ import (
"io"
"io"
"net/http"
"net/http"
"os"
"os"
"sync
/atomic
"
"sync"
"time"
"time"
)
)
// Downloader is an asynchronous downloader
// Downloader is an asynchronous downloader
type
Downloader
struct
{
type
Downloader
struct
{
URL
string
URL
string
Done
chan
bool
Done
chan
bool
resp
*
http
.
Response
resp
*
http
.
Response
out
*
os
.
File
out
*
os
.
File
completed
int64
completed
int64
size
int64
completedLock
sync
.
Mutex
err
error
size
int64
err
error
}
}
// DownloadOptions are optional flags that can be passed to Download function
// DownloadOptions are optional flags that can be passed to Download function
...
@@ -79,7 +80,9 @@ func (d *Downloader) AsyncRun() {
...
@@ -79,7 +80,9 @@ func (d *Downloader) AsyncRun() {
n
,
err
:=
in
.
Read
(
buff
[
:
])
n
,
err
:=
in
.
Read
(
buff
[
:
])
if
n
>
0
{
if
n
>
0
{
d
.
out
.
Write
(
buff
[
:
n
])
d
.
out
.
Write
(
buff
[
:
n
])
atomic
.
AddInt64
(
&
d
.
completed
,
int64
(
n
))
d
.
completedLock
.
Lock
()
d
.
completed
+=
int64
(
n
)
d
.
completedLock
.
Unlock
()
}
}
if
err
==
io
.
EOF
{
if
err
==
io
.
EOF
{
break
break
...
@@ -107,7 +110,10 @@ func (d *Downloader) Error() error {
...
@@ -107,7 +110,10 @@ func (d *Downloader) Error() error {
// Completed returns the bytes read so far
// Completed returns the bytes read so far
func
(
d
*
Downloader
)
Completed
()
int64
{
func
(
d
*
Downloader
)
Completed
()
int64
{
return
atomic
.
LoadInt64
(
&
d
.
completed
)
d
.
completedLock
.
Lock
()
res
:=
d
.
completed
d
.
completedLock
.
Unlock
()
return
res
}
}
// Download returns an asynchronous downloader that will donwload the specified url
// Download returns an asynchronous downloader that will donwload the specified url
...
...
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