Next: , Previous: , Up: Input/Output   [Contents][Index]

14.4 Bytevector Ports

This section describes binary input ports that read their input from given bytevectors, and binary output ports that accumulate their output and return it as a bytevector.

standard procedure: open-input-bytevector bytevector [start [end]]

Takes a bytevector and returns a binary input port that delivers bytes from the bytevector. If the bytevector is modified, the effect is unspecified.

The optional arguments start and end may be used to specify that the bytevector port delivers bytes from a portion of bytevector; if not given, start defaults to 0 and end defaults to (bytevector-length bytevector).

standard procedure: open-output-bytevector

Returns a binary output port that will accumulate bytes for retrieval by get-output-bytevector.

standard procedure: get-output-bytevector port

It is an error if port was not created with open-output-bytevector.

Returns a bytevector consisting of the bytes that have been output to the port so far in the order they were output. If the result bytevector is modified, the effect is unspecified.

procedure: call-with-output-bytevector procedure

The procedure is called with one argument, a binary output port. The values yielded by procedure are ignored. When procedure returns, call-with-output-bytevector returns the port’s accumulated output as a newly allocated bytevector.

This procedure could have been defined as follows:

(define (call-with-output-bytevector procedure)
  (let ((port (open-output-bytevector)))
    (procedure port)
    (get-output-bytevector port)))