(define-module (ldp content) #:use-module (oop goops) #:use-module (ice-9 binary-ports) #:use-module (rnrs bytevectors) #:use-module (rnrs)) (define-class () (port #:init-keyword #:port #:getter content-port) (additional #:init-keyword #:additional #:getter content-additional)) (define (the-boolean x) (unless (boolean? x) (scm-error 'wrong-type-arg "the-boolean" "Expected a boolean." '() (list x))) x) (define (the-binary-port x) (unless (binary-port? x) (scm-error 'wrong-type-arg "the-binary-port" "Expected a binary port." '() (list x))) x) (define (the-bytevector x) (unless (bytevector? x) (scm-error 'wrong-type-arg "the-bytevector" "Expected a bytevector." '() (list x))) x) (define-public (make-content port additional) (when (string? additional) (set! additional (string->utf8 additional))) (make #:port (the-binary-port port) #:additional additional)) (define-public (load-content content binary?) (let ((left (get-bytevector-all (content-port content))) (right (content-additional content))) (let ((nl (bytevector-length left)) (nr (bytevector-length right))) (let ((total (make-bytevector (+ nl nr)))) (bytevector-copy! left 0 total 0 nl) (bytevector-copy! right 0 total nl nr) (if binary? total (utf8->string total))))))