aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnonymized <anonymous@example.com>2018-01-20 02:39:23 +0100
committerAnonymized <anonymous@example.com>2018-01-20 02:42:51 +0100
commit06776fc99f243bdd7a3ea632f623a0bfafb357a7 (patch)
tree1ff0dcd1aac517bba39a418dc1196c549a0d591f
parent2034f421b3efe88e72cd626b36b74f453fdeaa66 (diff)
downloadgnunet-guile2-06776fc99f243bdd7a3ea632f623a0bfafb357a7.tar.gz
gnunet-guile2-06776fc99f243bdd7a3ea632f623a0bfafb357a7.zip
sync: add download as bytevector
-rw-r--r--gnunet/sync.scm53
1 files changed, 51 insertions, 2 deletions
diff --git a/gnunet/sync.scm b/gnunet/sync.scm
index 038e937..1985f60 100644
--- a/gnunet/sync.scm
+++ b/gnunet/sync.scm
@@ -16,8 +16,9 @@
16;;;; along with this program. If not, see <http://www.gnu.org/licenses/>. 16;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
17(define-module (gnunet sync)) 17(define-module (gnunet sync))
18 18
19(use-modules ((srfi srfi-1))) 19(use-modules ((ice-9 binary-ports)))
20(use-modules ((ice-9 threads))) 20(use-modules ((ice-9 threads)))
21(use-modules ((srfi srfi-1)))
21 22
22(use-modules ((gnunet))) 23(use-modules ((gnunet)))
23 24
@@ -105,7 +106,7 @@ code is non-zero; otherwise return #t."
105 106
106(define (search/task configuration uri callback) 107(define (search/task configuration uri callback)
107 (lambda () 108 (lambda ()
108 (let ((fs (fs-start configuration "gnunet-guile" (search/progress callback)))) 109 (let ((fs (fs-start configuration "c3b2" (search/progress callback))))
109 (let ((search-context (fs-search-start fs uri 1 %fs-search-option-none))) 110 (let ((search-context (fs-search-start fs uri 1 %fs-search-option-none)))
110 (scheduler-add-delayed %ten-seconds search/timeout) 111 (scheduler-add-delayed %ten-seconds search/timeout)
111 (scheduler-add-shutdown (search/task/shutdown search-context)))))) 112 (scheduler-add-shutdown (search/task/shutdown search-context))))))
@@ -126,3 +127,51 @@ code is non-zero; otherwise return #t."
126 (lambda (uri) (set! out (cons uri out)))))))) 127 (lambda (uri) (set! out (cons uri out))))))))
127 (join-thread thread)) 128 (join-thread thread))
128 out)) 129 out))
130
131;;; download
132
133(define (download/task/clean-up fs)
134 (lambda ()
135 (fs-stop fs)))
136
137(define (download/progress callback)
138 (lambda (info)
139 (let ((status (fs-progress-info-status info)))
140 (cond
141 ((eq? status %fs-status-download-completed)
142 (callback)
143 (scheduler-shutdown))
144 ((eq? status %fs-status-download-stopped)
145 (scheduler-add-now (download/task/clean-up (fs-progress-info-fs info))))))))
146
147
148(define (download/task/shutdown download-context)
149 (lambda ()
150 (fs-download-stop download-context #true)))
151
152(define (download/task configuration uri callback)
153 (lambda ()
154 (let ((fs (fs-start configuration "c3b2" (download/progress callback))))
155 (let ((download-context (fs-download-start fs uri 0 #:filename "c3b2.out")))
156 (scheduler-add-shutdown (download/task/shutdown download-context))))))
157
158(define (download-exec configuration uri callback)
159 (let ((configuration* (configuration-create)))
160 (configuration-load! configuration* configuration)
161 (let ((uri (string->uri uri)))
162 (scheduler-run (download/task configuration* uri callback)))))
163
164(define-public (download configuration uri)
165 "Download URI and return its bytevector"
166 (let ((out #f))
167 (let ((thread (call-with-new-thread
168 (lambda ()
169 (download-exec configuration
170 uri
171 (lambda ()
172 (call-with-input-file "c3b2.out"
173 (lambda (port)
174 (set! out (get-bytevector-all port)))
175 #:binary #t)))))))
176 (join-thread thread))
177 out))