From df3ae1e8927e242b0e9adb80276b3f0f9df31dae Mon Sep 17 00:00:00 2001 From: Michel Schinz Date: Fri, 21 Nov 2003 10:29:42 +0000 Subject: [PATCH] - added function base64-encode-string --- scsh/base64/README | 6 ++++++ scsh/base64/base64.scm | 12 +++++------- scsh/base64/interfaces.scm | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/scsh/base64/README b/scsh/base64/README index 1650780..6859bcf 100644 --- a/scsh/base64/README +++ b/scsh/base64/README @@ -21,6 +21,12 @@ Encode the contents of the INPUT-PORT and put the result on the OUTPUT-PORT. If no OUTPUT-PORT is given, encoding is done in a string, which is returned. +(base64-encode-string string [output-port]) -> port/string + +Encode the contents of the STRING and put the result on the +OUTPUT-PORT. If no OUTPUT-PORT is given, encoding is done in a string, +which is returned. + 2.2. Decoding (base64-decode-string string [output-port]) -> port/string diff --git a/scsh/base64/base64.scm b/scsh/base64/base64.scm index 72150b1..74ddcca 100644 --- a/scsh/base64/base64.scm +++ b/scsh/base64/base64.scm @@ -64,6 +64,11 @@ (define (base64-encode-port in-port . rest) (apply base64-encode-internal (lambda () (read-byte in-port)) rest)) +;; (base64-encode-string string [out-port]) +;; --> string or port +(define (base64-encode-string string . rest) + (apply base64-encode-port (make-string-input-port string) rest)) + (define (base64-encode-internal fetch-byte . rest) (let-optionals rest ((out-port (make-string-output-port))) (let ((output-char (char-writer out-port 76))) @@ -133,10 +138,3 @@ (loop full-bits full-bits-count)))))))) ;; Return port/output string. (if (null? rest) (string-output-port-output out-port) out-port))) - -;;; Tests -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -; (define (test) -; (let ((empty (byte-vector))) - diff --git a/scsh/base64/interfaces.scm b/scsh/base64/interfaces.scm index 09a65fb..2014885 100644 --- a/scsh/base64/interfaces.scm +++ b/scsh/base64/interfaces.scm @@ -1,5 +1,6 @@ (define-interface base64-interface (export base64-encode-vector base64-encode-port + base64-encode-string base64-decode-string base64-decode-port))