steel/ports
close-input-port
Close an input port. If the port is a file, the file will be closed.
(close-input-port input-port?) -> void
close-output-port
Close an output port. If the port is a file, the file will be closed.
(close-output-port output-port?) -> void
close-port
Close a port. If the port is a file, the file will be closed.
(close-port port?) -> void
eof-object
Returns an EOF object.
(eof-object) -> eof-object?
get-output-bytevector
Extracts the contents from a port created with open-output-bytevector.
(get-output-bytevector port?) -> bytes?
get-output-string
Extracts the string contents from a port created with open-output-string.
(get-output-string port?) -> string?
input-port?
Checks if a given value is an input port
(input-port? any/c) -> bool?
Examples
> (input-port? (stdin)) ;; => #true
> (input-port? "foo") ;; => #false
open-input-bytevector
Creates an input port from a bytevector, that will return the bytevector contents.
(open-input-bytevector bytes?) -> input-port?
open-input-file
Takes a filename path referring to an existing file and returns an input port. Raises an error
if the file does not exist
(open-input-file string?) -> input-port?
Examples
> (open-input-file "foo-bar.txt") ;; => #<input-port:foo-bar.txt>
> (open-input-file "file-does-not-exist.txt")
error[E08]: Io
┌─ :1:2
│
1 │ (open-input-file "foo-bar.txt")
│ ^^^^^^^^^^^^^^^ No such file or directory (os error 2)
open-input-string
Creates an input port from a string, that will return the string contents.
(open-input-string string?) -> input-port?
open-output-bytevector
Creates an output port that accumulates what is written into a bytevector.
These bytes can be recovered calling get-output-bytevector.
(open-output-bytevector) -> output-port?
Examples
(define out (open-output-bytevector))
(write-byte 30 out)
(write-byte 250 out)
(get-output-bytevector out) ;; => (bytes 30 250)
open-output-file
Takes a filename path referring to a file to be created and returns an output port.
(open-output-file string?) -> output-port?
Examples
> (open-output-file "foo-bar.txt") ;; => #<output-port:foo-bar.txt>
open-output-string
Creates an output port that accumulates what is written into a string.
This string can be recovered calling get-output-string.
(open-output-string) -> output-port?
Examples
(define out (open-output-string))
(write-char "α" out)
(write-char "ω" out)
(get-output-string out) ;; => "αω"
output-port?
Checks if a given value is an output port
(output-port? any/c) -> bool?
Examples
> (define output (open-output-file "foo.txt"))
> (output-port? output) ;; => #true
read-line-from-port
Reads a line from the given port, including the ‘\n’ at the end.
Use of this procedure is discouraged in favor of the (read-line) procedure, which is included in the scheme spec and therefore more portable.
(read-line-from-port port?) -> string?
stdin
Gets the port handle to stdin
(stdin) -> input-port?
Examples
> (stdin) ;; => #<input-port:stdin>
would-block-object?
Returns #t if the value is an EOF object.
(eof-object? any/c) -> bool?