call-with-bytevector-output-port - call a procedure with a bytevector output
port
(import (rnrs)) ;R6RS
(import (rnrs io ports)) ;R6RS
(call-with-bytevector-output-port proc)
(call-with-bytevector-output-port proc maybe-transcoder)
Creates an output port that accumulates the bytes written to it and calls
proc with that output port as an argument. Whenever proc
returns, a bytevector consisting of all of the port's accumulated bytes
(regardless of the port’s current position) is returned and the port is
closed.
The transcoder associated with the output port is determined as
for a call to open-bytevector-output-port(3scm).
Returns a single value; a bytevector.
(call-with-bytevector-output-port
(lambda (p)
(put-u8 p 7)))
=> #vu8(7)
(call-with-bytevector-output-port
(lambda (p)
(put-string p "0123"))
(native-transcoder))
=> #vu8(48 49 50 51)
This procedure is commonly used when creating bytevectors piecemeal.
This procedure is unique to R6RS. It is a wrapper around
open-bytevector-output-port(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, proc must be a procedure that can accept one
argument, and maybe-transcoder must be a transcoder or
#f.
open-bytevector-output-port(3scm),
open-bytevector-input-port(3scm)
This procedure is new to the reworked I/O in R6RS.