(import (rnrs)) ;R6RS (import (rnrs io ports)) ;R6RS
(get-bytevector-some binary-input-port)
If bytes become available, returns a freshly allocated bytevector containing the initial available bytes (at least one), and updates binary-input-port to point just past these bytes.
If no input bytes are seen before an end of file is reached, the end-of-file object is returned.
(import (rnrs))
(define (char-rot13 c)
(cond ((and (char<=? #\a c #\z))
(integer->char
(+ (char->integer #\a)
(mod (+ (- (char->integer c) (char->integer #\a)) 13)
26))))
((and (char<=? #\A c #\Z))
(integer->char
(+ (char->integer #\A)
(mod (+ (- (char->integer c) (char->integer #\A)) 13)
26))))
(else c)))
;; This example unnecessarily works with binary ports
;; to demonstrate get-bytevector-some.
(let ((in (standard-input-port))
(out (standard-output-port)))
(let lp ()
(let ((bv (get-bytevector-some in)))
(unless (eof-object? bv)
(do ((i 0 (+ i 1)))
((= i (bytevector-length bv)))
(let* ((b (bytevector-u8-ref bv i))
(c (integer->char b))
(b^ (char->integer (char-rot13 c))))
(bytevector-u8-set! bv i b^)))
(put-bytevector out bv)
(flush-output-port out)
(lp)))))
TCP sockets produce data in bursts and end with an infinite sequence of end-of-file objects (or an I/O error). UDP sockets produce data in one burst per datagram and can also signal errors via ICMP packets. Interactive terminals produce data in bursts (one per character or approximately one per line), and they can also produce end-of-file objects (typically mapped to Ctrl-D).
The other procedures for reading from binary input ports, i.e., get-bytevector-n(3scm), get-bytevector-n!(3scm), and get-bytevector-all(3scm), specify a length or read all data and block as necessary to read that number of bytes, or until an end-of-file is received. These procedures therefore don't work when the data is produced in bursts that are not separated by end-of-file objects.
https://github.com/schemedoc/manpages/.