| call-with-bytevector-output-port(3scm) | Scheme Programmer's Manual | call-with-bytevector-output-port(3scm) |
NAME
call-with-bytevector-output-port - call a procedure with a bytevector output port
LIBRARY
(import (rnrs)) ;R6RS (import (rnrs io ports)) ;R6RS
SYNOPSIS
(call-with-bytevector-output-port proc) (call-with-bytevector-output-port proc maybe-transcoder)
DESCRIPTION
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).
RETURN VALUES
Returns a single value; a bytevector.
EXAMPLES
(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)
APPLICATION USAGE
This procedure is commonly used when creating bytevectors piecemeal.
COMPATIBILITY
This procedure is unique to R6RS. It is a wrapper around open-bytevector-output-port(3scm).
ERRORS
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.
SEE ALSO
open-bytevector-output-port(3scm), open-bytevector-input-port(3scm)
STANDARDS
R6RS
HISTORY
This procedure is new to the reworked I/O in R6RS.
AUTHORS
This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.
| 2023-02-15 |