- added function base64-encode-string

This commit is contained in:
Michel Schinz 2003-11-21 10:29:42 +00:00
parent 654f9004e2
commit df3ae1e892
3 changed files with 12 additions and 7 deletions

View File

@ -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

View File

@ -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)))

View File

@ -1,5 +1,6 @@
(define-interface base64-interface
(export base64-encode-vector
base64-encode-port
base64-encode-string
base64-decode-string
base64-decode-port))