put-u8, write-u8 - write a byte to a binary output port
(import (rnrs)) ;R6RS
(import (rnrs io ports)) ;R6RS
(import (scheme base)) ;R7RS
(put-u8 binary-output-port byte) ;R6RS
(write-u8 byte) ;R7RS
(write-u8 byte binary-output-port) ;R7RS
Writes the byte to the given binary-output-port.
- Chibi Scheme
- The current-output-port(3scm) at program start is both textual and
binary. It should normally not be possible to use write-u8 on the
current output port before rebinding it to a binary output port (which is
not possible in R6RS).
- R6RS
- Returns unspecified values.
- R7RS
- Returns a unspecified value.
;; R7RS code to create a file with the single line "A"
(call-with-port (open-output-file "test.txt")
(lambda (p)
(write-u8 65 p)
(write-u8 10 p)))
Commonly used in applications that create binary files or other binary data.
There is often a mix of single bytes intermixed with larger writes with
put-bytevector(3scm).
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
- The wrong number of arguments was passed or an argument was outside its
domain. In particular, byte must be an exact integer between 0 and
255.
- &i/o-write (R6RS)
- There was an I/O error during the write operation.
- &i/o-port (R6RS)
- If this is included as part of an I/O condition then the port related to
the I/O error can be retrieved with i/o-error-port(3scm).
- R7RS
- The assertions described above are errors. Implementations may signal an
error, extend the procedure's domain of definition to include such
arguments, or fail catastrophically.
The put-u8 procedure is new to the reworked I/O system introduced with
R6RS. The write-u8 procedure is new in R7RS and is similar to
write-char(3scm) but works with binary output ports, which did not
exist in R5RS.