Warning: This is the manual of the legacy Guile 2.0 series. You may want to read the manual of the current stable series instead.

Next: , Previous: , Up: R6RS I/O Ports   [Contents][Index] Binary Output

Binary output ports can be created with the procedures below.

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.

  (lambda ()
  (lambda (port get-bytevector)
    (display "hello" port)

⇒ #vu8(104 101 108 108 111)

The transcoder argument is currently not supported.

Scheme Procedure: make-custom-binary-output-port id write! get-position set-position! close
C Function: scm_make_custom_binary_output_port (id, write!, get-position, set-position!, close)

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 passed 0 as 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 (see make-custom-binary-input-port).

Writing to a binary output port can be done using the following procedures:

Scheme Procedure: put-u8 port octet
C Function: scm_put_u8 (port, octet)

Write octet, an integer in the 0–255 range, to port, a binary output port.

Scheme Procedure: put-bytevector port bv [start [count]]
C Function: scm_put_bytevector (port, bv, start, count)

Write the contents of bv to port, optionally starting at index start and limiting to count octets.

Next: , Previous: , Up: R6RS I/O Ports   [Contents][Index]