me
/
guix
Archived
1
0
Fork 0

progress: Add a download-size argument to progress-report-port.

* guix/progress.scm (progress-report-port): Add a download-size argument.
master
Mathieu Othacehe 2021-05-20 10:52:27 +02:00
parent ea55e1355b
commit 4f2fa2f980
No known key found for this signature in database
GPG Key ID: 8354763531769CA6
1 changed files with 13 additions and 3 deletions

View File

@ -347,15 +347,25 @@ should be a <progress-reporter> object."
(report total) (report total)
(loop total (get-bytevector-n! in buffer 0 buffer-size)))))))) (loop total (get-bytevector-n! in buffer 0 buffer-size))))))))
(define* (progress-report-port reporter port #:key (close? #t)) (define* (progress-report-port reporter port
#:key
(close? #t)
download-size)
"Return a port that continuously reports the bytes read from PORT using "Return a port that continuously reports the bytes read from PORT using
REPORTER, which should be a <progress-reporter> object. When CLOSE? is true, REPORTER, which should be a <progress-reporter> object. When CLOSE? is true,
PORT is closed when the returned port is closed." PORT is closed when the returned port is closed.
When DOWNLOAD-SIZE is passed, do not read more than DOWNLOAD-SIZE bytes from
PORT. This is important to avoid blocking when the remote side won't close
the underlying connection."
(match reporter (match reporter
(($ <progress-reporter> start report stop) (($ <progress-reporter> start report stop)
(let* ((total 0) (let* ((total 0)
(read! (lambda (bv start count) (read! (lambda (bv start count)
(let ((n (match (get-bytevector-n! port bv start count) (let* ((count (if download-size
(min count (- download-size total))
count))
(n (match (get-bytevector-n! port bv start count)
((? eof-object?) 0) ((? eof-object?) 0)
(x x)))) (x x))))
(set! total (+ total n)) (set! total (+ total n))