(import r7rs) (define-library (srfi 207) (import (scheme base) (scheme read) (scheme case-lambda) (only (scheme char) char-whitespace? char-ci=? char-cihex-string bytestring->list make-bytestring make-bytestring! hex-string->bytevector make-bytestring-generator bytestring-pad bytestring-pad-right bytestring-trim bytestring-trim-right bytestring-trim-both bytestring-replace bytestring-index bytestring-index-right bytestring-break bytestring-span bytestring>? bytestring=? bytestring-error? bytestring-join bytestring-split write-textual-bytestring write-binary-bytestring ) ;; (srfi 207 base64) (export bytevector->base64 base64->bytevector) ;; (srfi 207 read) (export read-textual-bytestring) (begin (register-feature! 'srfi-207) ;;; SNB read syntax. ;;; ;;; Thanks to the authors of the srfi-4 module for providing an ;;; example of how this should work, and to Felix for providing ;;; further help. (define (bytestring-or-vector-read-error port x) (##sys#read-error port "illegal bytestring/vector syntax" x)) (define (read-bytestring-or-vector port) (let* ((sexp (read port)) (tag (and (symbol? sexp) sexp))) (case tag ((u16) (list->u16vector (read port))) ((u32) (list->u32vector (read port))) ((u64) (list->u64vector (read port))) ((u8) (case (peek-char port) ((#\() (list->u8vector (read port))) ((#\") (read-textual-bytestring #f port)) (else => (lambda (del) (bytestring-or-vector-read-error port del))))) (else (bytestring-or-vector-read-error port tag))))) (set! ##sys#user-read-hook (let ((old-hook ##sys#user-read-hook)) (lambda (char port) (if (eqv? char #\u) (read-bytestring-or-vector port) (old-hook char port))))) ))