From 045e3496be5cc0598da18f82968051b0d39680f3 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 9 Nov 2024 14:04:47 -0500 Subject: base64: Simplify reading from bytevector in base64-encode. --- chickadee/base64.scm | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/chickadee/base64.scm b/chickadee/base64.scm index 8fe384c..6575785 100644 --- a/chickadee/base64.scm +++ b/chickadee/base64.scm @@ -122,17 +122,14 @@ return a bytevector containing the decoded data." (let ((offset (* i 3))) (cond ((< i groups) - (let ((x (logior (ash (bytevector-u8-ref bv offset) 16) - (ash (bytevector-u8-ref bv (1+ offset)) 8) - (bytevector-u8-ref bv (+ offset 2))))) + (let ((x (bytevector-uint-ref bv offset (endianness big) 3))) (put-char port (encode (ash (logand x #xfc0000) -18))) (put-char port (encode (ash (logand x #x03f000) -12))) (put-char port (encode (ash (logand x #x000fc0) -6))) (put-char port (encode (logand x #x00003f))) (lp (1+ i)))) ((eq? padding 1) - (let ((x (logior (ash (bytevector-u8-ref bv offset) 8) - (bytevector-u8-ref bv (1+ offset))))) + (let ((x (bytevector-u16-ref bv offset (endianness big)))) (put-char port (encode (ash (logand x #xfc00) -10))) (put-char port (encode (ash (logand x #x03f0) -4))) (put-char port (encode (ash (logand x #x000f) 2))) -- cgit v1.2.3