6.12.10.2 Bytevector Ports

Scheme Procedure: open-bytevector-input-port bv [transcoder]
C Function: scm_open_bytevector_input_port (bv, transcoder)

Return an input port whose contents are drawn from bytevector bv (see Bytevectors).

The transcoder argument is currently not supported.

Scheme Procedure: open-bytevector-output-port [transcoder]
C Function: scm_open_bytevector_output_port (transcoder)

Return two values: a binary output port and a procedure. The latter should be called with zero arguments to obtain a bytevector containing the data accumulated by the port, as illustrated below.

(call-with-values
  (lambda ()
    (open-bytevector-output-port))
  (lambda (port get-bytevector)
    (display "hello" port)
    (get-bytevector)))

⇒ #vu8(104 101 108 108 111)

The transcoder argument is currently not supported.

Scheme Procedure: call-with-output-bytevector proc

Call the one-argument procedure proc with a newly created bytevector output port. When the function returns, the bytevector composed of the characters written into the port is returned. proc should not close the port.

Scheme Procedure: call-with-input-bytevector bytevector proc

Call the one-argument procedure proc with a newly created input port from which bytevector’s contents may be read. The values yielded by the proc is returned.