picrin/t/byteio.scm

35 lines
898 B
Scheme

(import (scheme base)
(scheme write)
(scheme file))
(let ((string-port (open-input-string "hello")))
(display "read-string: ")
(write (read-string 4 string-port))
(newline)
(display "read-string more: ")
(write (read-string 4 string-port))
(newline))
(let ((byte-port (open-input-bytevector (bytevector 1 2 3 4 5 6 7 8)))
(buf (make-bytevector 4 98)))
(display "read-u8: ")
(write (read-u8 byte-port))
(newline)
(display "peek-u8: ")
(write (peek-u8 byte-port))
(newline)
(display "read-bytevector: ")
(write (read-bytevector 4 byte-port))
(newline)
(display "read-bytevector!: read size: ")
(write (read-bytevector! buf byte-port 1 3))
(display ": read content: ")
(write buf)
(newline)
(display "read-bytevector!: read size: ")
(write (read-bytevector! buf byte-port))
(display ": read content: ")
(write buf)
(newline))