- added function base64-encode-string
This commit is contained in:
parent
654f9004e2
commit
df3ae1e892
|
@ -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,
|
OUTPUT-PORT. If no OUTPUT-PORT is given, encoding is done in a string,
|
||||||
which is returned.
|
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
|
2.2. Decoding
|
||||||
|
|
||||||
(base64-decode-string string [output-port]) -> port/string
|
(base64-decode-string string [output-port]) -> port/string
|
||||||
|
|
|
@ -64,6 +64,11 @@
|
||||||
(define (base64-encode-port in-port . rest)
|
(define (base64-encode-port in-port . rest)
|
||||||
(apply base64-encode-internal (lambda () (read-byte 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)
|
(define (base64-encode-internal fetch-byte . rest)
|
||||||
(let-optionals rest ((out-port (make-string-output-port)))
|
(let-optionals rest ((out-port (make-string-output-port)))
|
||||||
(let ((output-char (char-writer out-port 76)))
|
(let ((output-char (char-writer out-port 76)))
|
||||||
|
@ -133,10 +138,3 @@
|
||||||
(loop full-bits full-bits-count))))))))
|
(loop full-bits full-bits-count))))))))
|
||||||
;; Return port/output string.
|
;; Return port/output string.
|
||||||
(if (null? rest) (string-output-port-output out-port) out-port)))
|
(if (null? rest) (string-output-port-output out-port) out-port)))
|
||||||
|
|
||||||
;;; Tests
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
; (define (test)
|
|
||||||
; (let ((empty (byte-vector)))
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
(define-interface base64-interface
|
(define-interface base64-interface
|
||||||
(export base64-encode-vector
|
(export base64-encode-vector
|
||||||
base64-encode-port
|
base64-encode-port
|
||||||
|
base64-encode-string
|
||||||
base64-decode-string
|
base64-decode-string
|
||||||
base64-decode-port))
|
base64-decode-port))
|
||||||
|
|
Loading…
Reference in New Issue