summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2020-04-06 06:54:16 +0200
committerRicardo Wurmus <rekado@elephly.net>2020-04-06 06:54:16 +0200
commitbb2fe926b496dc44f783430ab16f5219bae36e81 (patch)
treef8a38802f51e7a4a1048f8d67b15d6fe1503f968
parent817500299fea7ccfa75c442904abcb352da0d100 (diff)
send-email: Add definition of dump-port.
-rw-r--r--mumi/send-email.scm27
1 files changed, 26 insertions, 1 deletions
diff --git a/mumi/send-email.scm b/mumi/send-email.scm
index 02a5364..2fbcbda 100644
--- a/mumi/send-email.scm
+++ b/mumi/send-email.scm
@@ -16,7 +16,6 @@
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (mumi send-email)
- #:use-module ((guix build utils) #:select (dump-port))
#:use-module (gcrypt base64)
#:use-module (rnrs io ports)
#:use-module (rnrs bytevectors)
@@ -30,6 +29,32 @@
;; This variable is looked up by 'mu-message-send', uh!
(define-public mu-debug 0)
+;; From (guix build utils)
+(define* (dump-port in out
+ #:key (buffer-size 16384)
+ (progress (lambda (t k) (k))))
+ "Read as much data as possible from IN and write it to OUT, using chunks of
+BUFFER-SIZE bytes. Call PROGRESS at the beginning and after each successful
+transfer of BUFFER-SIZE bytes or less, passing it the total number of bytes
+transferred and the continuation of the transfer as a thunk."
+ (define buffer
+ (make-bytevector buffer-size))
+
+ (define (loop total bytes)
+ (or (eof-object? bytes)
+ (let ((total (+ total bytes)))
+ (put-bytevector out buffer 0 bytes)
+ (progress total
+ (lambda ()
+ (loop total
+ (get-bytevector-n! in buffer 0 buffer-size)))))))
+
+ ;; Make sure PROGRESS is called when we start so that it can measure
+ ;; throughput.
+ (progress 0
+ (lambda ()
+ (loop 0 (get-bytevector-n! in buffer 0 buffer-size)))))
+
(define (pipe-pair command)
"Run COMMAND as a separate process and return three values: its PID, an
output port to write on COMMAND's standard input, and an input port to read