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)
(if (zero? n)
""
(let ((res (read-string n (if (pair? o) (car o) (current-input-port)))))
(if (eof-object? res)
res
(string->utf8 res)))))
#u8()
(let ((in (if (pair? o) (car o) (current-input-port)))
(res (make-bytevector n)))
(let lp ((i 0))
(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)
(if (>= start end)