Fixing read-bytevector to use read-u8 instead of the hacked definition in terms of read-string.

This commit is contained in:
Alex Shinn 2012-10-13 22:37:24 +09:00
parent 60c96d76a4
commit b5046925f7

View file

@ -43,11 +43,18 @@
(define (read-bytevector n . o) (define (read-bytevector n . o)
(if (zero? n) (if (zero? n)
"" #u8()
(let ((res (read-string n (if (pair? o) (car o) (current-input-port))))) (let ((in (if (pair? o) (car o) (current-input-port)))
(if (eof-object? res) (res (make-bytevector n)))
res (let lp ((i 0))
(string->utf8 res))))) (if (>= i n)
res
(let ((x (read-u8 in)))
(cond ((eof-object? x)
(if (zero? i) x (subbytes res 0 i)))
(else
(bytevector-u8-set! res i x)
(lp (+ i 1))))))))))
(define (read-bytevector! vec start end . o) (define (read-bytevector! vec start end . o)
(if (>= start end) (if (>= start end)