Chicken » Module (chicken io)

## Module (chicken io)

This module provides various Input/Output extensions.

### read-list

read-list #!optional PORT READER MAXprocedure

  Call READER up to MAX times and collect its output in a list. If MAX is `#f`, read until end of file.

  The reader is called with one argument: PORT.

  READER defaults to `read`, MAX to `#f` and PORT to `current-input-port`, so if you call it with no arguments, it will read all remaining s-expressions from the current input port.

### read-buffered

read-buffered #!optional PORTprocedure

  Reads any remaining data buffered after previous read operations on PORT. If no remaining data is currently buffered, an empty string is returned. This procedure will never block. Currently only useful for string-, process- and tcp ports.

### read-byte

### write-byte

read-byte #!optional PORTprocedure
write-byte BYTE #!optional PORTprocedure

  Read/write a byte to the port given in PORT, which default to the values of `(current-input-port)` and `(current-output-port)`, respectively.

### read-line

### write-line

read-line #!optional PORT LIMITprocedure
write-line STRING #!optional PORTprocedure

  Line-input and -output. PORT defaults to the value of `(current-input-port)` and `(current-output-port)`, respectively. If the optional argument LIMIT is given and not `#f`, then `read-line` reads at most LIMIT characters per line. `read-line` returns a string without the terminating newline and `write-line` adds a terminating newline before outputting.

### read-lines

read-lines #!optional PORT MAXprocedure

  Read MAX or fewer lines from PORT. MAX defaults to `most-positive-fixnum` and PORT defaults to the value of `(current-input-port)`. Returns a list of strings, each string representing a line read, not including any line separation character(s).

### read-string

### read-string!

read-string #!optional NUM PORTprocedure
read-string! NUM STRING #!optional PORT STARTprocedure

  Read or write NUM characters from/to PORT, which defaults to the value of `(current-input-port)` or `(current-output-port)`, respectively.

  If NUM is `#f` or not given, then all data up to the end-of-file is read, or, in the case of `write-string` the whole string is written. If no more input is available, `read-string` returns `#!eof`.

  `read-string!` reads destructively into the given STRING argument, but never more characters than would fit into STRING. If START is given, then the read characters are stored starting at that position. `read-string!` returns the actual number of characters read.

### read-bytevector

read-bytevector #!optional NUM PORTprocedure

  Read NUM bytes from PORT, which defaults to the value of `(current-input-port)`. `read-bytevector` allocates a new buffer and returns it (or the end-of-file object, if at the end of the input file).

  If NUM is optional and not given, then all remaining input is read or the whole bytevector is read/written.

### read-bytevector!

`(read-bytevector! BYTEVECTOR [PORT START END])`procedure

  Read bytes from `PORT` into `BYTEVECTOR`. `PORT` defaults to the value of `(current-input-port)` and returns the actual number of bytes read.

  `START` and `END` designate the range of bytes that should be filled with input from `PORT`. If `END` exceeeds the length of `BYTEVECTOR` only as much data is read as fits into the destination buffer.

### write-bytevector

`(write-bytevector BYTEVECTOR [PORT START END])`procedure

  Write bytes from `BYTEVECTOR` to `PORT`. `PORT` defaults to the value of `(current-output-port)`.

  `START` and `END` designate the range of bytes that should be written. If `END` exceeeds the length of `BYTEVECTOR` only as much data is written as is available.

### read-token

read-token PREDICATE #!optional PORTprocedure

  Reads characters from PORT (which defaults to the value of `(current-input-port)`) and calls the procedure PREDICATE with each character until PREDICATE returns false. Returns a string with the accumulated characters.

Previous: Module (chicken gc)

Next: Module (chicken irregex)