From 76ee21f9a383be2c2f09a46a42ec53acff61ad8a Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Tue, 15 Aug 2017 11:54:55 +0000 Subject: [PATCH] Non blocking downloads utility (see how they can be used in the Comtrade package). --- .../GrafoscopioUtils.class.st | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st b/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st index 8578134..2fcec62 100644 --- a/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st +++ b/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st @@ -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