Non blocking downloads utility (see how they can be used in the Comtrade package).

This commit is contained in:
Offray Vladimir Luna Cárdenas 2017-08-15 11:54:55 +00:00 committed by SantiagoBragagnolo
parent f0c214fbd9
commit cd1c6bd9e8
1 changed files with 19 additions and 1 deletions

View File

@ -11,7 +11,7 @@ Class {
{ #category : #'graphical interface' }
GrafoscopioUtils class >> downloadingFrom: downloadUrl withMessage: aString into: location [
| fileName |
fileName := downloadUrl segments last.
fileName := (self sanitize: downloadUrl) segments last.
(location / fileName) ensureDelete.
[: bar |
bar title: aString.
@ -28,6 +28,24 @@ GrafoscopioUtils class >> downloadingFrom: downloadUrl withMessage: aString into
] asJob run.
]
{ #category : #'graphical interface' }
GrafoscopioUtils class >> getContentsFrom: url withMessage: aString [
| client |
[: bar |
bar title: aString.
[client := ZnClient new
enforceHttpSuccess: true;
get: (url);
signalProgress: true
]
on: HTTPProgress
do: [ :progress |
progress isEmpty ifFalse: [ bar current: progress percentage ].
progress resume ].
] asJob run.
^ client contents.
]
{ #category : #private }
GrafoscopioUtils class >> sanitize: url [
"I remove white spaces in url's and prepend 'http://' to urls when it is ommited, so