Binary output ports can be created with the procedures below.
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.
Return a new custom binary output port named id (a string) whose output is sunk by invoking write! and passing it a bytevector, an index where bytes should be read from this bytevector, and the number of bytes to be “written”. The
write!procedure must return an integer indicating the number of bytes actually written; when it is passed0as the number of bytes to write, it should behave as though an end-of-file was sent to the byte sink.The other arguments are as for
make-custom-binary-input-port(seemake-custom-binary-input-port).
Writing to a binary output port can be done using the following procedures: