Fix eof-object bug in read-exactly-n-bytes

This commit is contained in:
Lassi Kortela 2021-09-20 12:21:36 +03:00
parent c93b9b7486
commit 2b08ec5e25
1 changed files with 5 additions and 2 deletions

View File

@ -27,8 +27,11 @@
(loop (+ i 1))))))
(define (read-exactly-n-bytes n)
(let ((bytes (read-bytevector n)))
(if (= n (bytevector-length bytes)) bytes (error "Short read"))))
(let* ((bytex (read-bytevector n))
(bytes (if (eof-object? bytex) (bytevector) bytex)))
(if (< (bytevector-length bytes) n)
(error "Short read / wanted / got" n (bytevector-length bytes))
bytes)))
;;