base64: Turn into a regular Guile module.

* guix/base64.scm: Replace 'library' form with 'define-module'.
This commit is contained in:
Ludovic Courtès 2017-05-25 14:11:22 +02:00
parent faa6bdf8ad
commit 4862a98be4
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 189 additions and 188 deletions

View File

@ -5,6 +5,7 @@
;; February 12, 2014. ;; February 12, 2014.
;; ;;
;; Some optimizations made by Ludovic Courtès <ludo@gnu.org>, 2015. ;; Some optimizations made by Ludovic Courtès <ludo@gnu.org>, 2015.
;; Turned into a Guile module (instead of R6RS).
;; ;;
;; This program is free software: you can redistribute it and/or modify ;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by ;; it under the terms of the GNU General Public License as published by
@ -42,23 +43,20 @@
;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;; DEALINGS IN THE SOFTWARE. ;; DEALINGS IN THE SOFTWARE.
#!r6rs
;; RFC 4648 Base-N Encodings ;; RFC 4648 Base-N Encodings
(library (guix base64) (define-module (guix base64)
(export base64-encode #:export (base64-encode
base64-decode base64-decode
base64-alphabet base64-alphabet
base64url-alphabet base64url-alphabet
get-delimited-base64 get-delimited-base64
put-delimited-base64) put-delimited-base64)
(import (rnrs) #:use-module (rnrs)
(only (srfi :13 strings) #:use-module ((srfi srfi-13)
string-index #:select (string-index
string-prefix? string-suffix? string-prefix? string-suffix?
string-concatenate string-trim-both) string-concatenate string-trim-both)))
(only (guile) ash logior))
(define-syntax define-alias (define-syntax define-alias
@ -68,6 +66,7 @@
;; Force the use of Guile's own primitives to avoid the overhead of its 'fx' ;; Force the use of Guile's own primitives to avoid the overhead of its 'fx'
;; procedures. ;; procedures.
(define-alias fxbit-field bitwise-bit-field) (define-alias fxbit-field bitwise-bit-field)
(define-alias fxarithmetic-shift ash) (define-alias fxarithmetic-shift ash)
(define-alias fxarithmetic-shift-left ash) (define-alias fxarithmetic-shift-left ash)
@ -143,6 +142,7 @@
;; Decodes a base64 string. The string must contain only pure ;; Decodes a base64 string. The string must contain only pure
;; unpadded base64 data. ;; unpadded base64 data.
(define base64-decode (define base64-decode
(case-lambda (case-lambda
((str) ((str)
@ -201,6 +201,7 @@
;; the given port. Returns two values: a string with the type and a ;; the given port. Returns two values: a string with the type and a
;; bytevector containing the base64 decoded data. The second value ;; bytevector containing the base64 decoded data. The second value
;; is the eof object if there is an eof before the BEGIN delimiter. ;; is the eof object if there is an eof before the BEGIN delimiter.
(define (get-delimited-base64 port) (define (get-delimited-base64 port)
(define (get-first-data-line port) (define (get-first-data-line port)
;; Some MIME data has header fields in the same format as mail ;; Some MIME data has header fields in the same format as mail
@ -249,4 +250,4 @@
line-length #f base64-alphabet port) line-length #f base64-alphabet port)
(display (string-append "\n-----END " type "-----\n") port)) (display (string-append "\n-----END " type "-----\n") port))
((port type bv) ((port type bv)
(put-delimited-base64 port type bv 76))))) (put-delimited-base64 port type bv 76))))