Skip to content

I/O

Scheme Procedure: read-textual-bytestring prefix [port]

Reads a string in the external format described in this SRFI from port and return it as a bytevector. If the prefix argument is false, this procedure assumes that "#u8" has already been read from port. If port is omitted, it defaults to the value of (current-input-port). If the characters read are not in the external format, an error satisfying bytestring-error? is raised.

emacs-lisp
(call-with-port
    (open-input-string "#u8\"AB\\xad;\\xf0;\\x0d;CD\"")
  (lambda (port) (read-textual-bytestring #t port)))
#u8(#x41 #x42 #xad #xf0 #x0d #x43 #x44)

Scheme Procedure: write-textual-bytestring bytevector [port]

Writes bytevector in the external format described in this SRFI to port. Bytes representing non-graphical ASCII characters are unencoded: all other bytes are encoded with a single letter if possible, otherwise with a \x escape. If port is omitted, it defaults to the value of (current-output-port).

emacs-lisp
(call-with-port
    (open-output-string)
  (lambda (port)
    (write-textual-bytestring
     #u8(#x9 #x41 #x72 #x74 #x68 #x75 #x72 #xa)
     port)
    (get-output-string port)))
"#u8\"\\tArthur\\n\""

Scheme Procedure: write-binary-bytestring port arg …

Outputs each arg to the binary output port port using the same interpretations as bytestring, but without creating any bytevectors. The args are validated before any bytes are written to port; if they are ill-formed, an error satisfying bytestring-error? is raised.

emacs-lisp
(call-with-port
    (open-output-bytevector)
  (lambda (port)
    (write-binary-bytestring port #\Z #x61 #x70 "hod")
    (get-output-bytevector port)))
#u8"Zaphod"