2021-02-05

(sph io)

port and file input/output.

part of sph-lib

library description

part of (sph io), which additionally exports (rnrs io ports) and (rnrs io simple)

module name

(sph io)

exported bindings

procedure: bytevector->file a path ->
procedure: call-with-input-files proc paths ... ->
procedure: call-with-pipe proc ->
equivalent to (call-with-pipes 1 proc)
procedure: call-with-pipes count proc ->
integer procedure:{[pipe-n-in pipe-n-out] ... -> any} -> any
the pipes are not automatically closed.
reading from the input side might block as long as the output side is not yet closed
procedure: call-with-temp-file proc [path name-part] ->
procedure:{port -> any} -> any
call proc with an output port to a temporary file.
the file is deleted after proc returns or the current process exits.
result is the result of calling proc
procedure: each-u8 proc port ->
procedure:{integer -> any} port -> unspecified
call proc with each eight bit integer read from port until end-of-file is reached.
procedure: file->bytevector path\file ->
string -> bytevector
open or use an opened file, read until end-of-file is reached and return a bytevector of file contents
procedure: file->file path-input path-output #:copy #:input-binary #:output-binary #:append? ->
string string procedure:{port port -> any} [#:input-binary boolean #:output-binary? boolean] -> any
open path-input for reading and path-output for writing and copy all contents of the input file or call proc with the ports.
the ports are closed when copy returns
procedure: file->port path port ->
string port ->
copy all content of file at path to port
procedure: file->string path/file ->
string/file -> string
open or use an opened file, read until end-of-file is reached and return a string of file contents
procedure: files->port paths output ->
(string ...) port ->
procedure: named-pipe [path permissions] ->
[string integer] -> string:path
create a named pipe (fifo).
named pipes persist in the filesystem
procedure: named-pipe-chain first-input last-output proc ... ->
port/true port/true procedure:{pipe-input pipe-output -> false/any} ... -> (procedure-result ...)
creates a named pipe shared between a procedure output and the next procedure input.
procedure results are saved in a list which is returned unless a result is false
in which case it stops and results up to that point are returned.
the named pipes persist in the file system and are not automatically deleted
procedure: pipe-chain first-input last-output proc ... ->
port/true port/true procedure:{pipe-input pipe-output -> false/any} ... -> (procedure-result ...)
create a pipe for each procedure output and the next procedure input and call procedures with the respective input/output-ports.
if any result is false then stop and return results up to that point.
the pipe endpoints are not automatically closed to allow the use of threads in procedures
procedure: port->bytevector a ->
procedure: port->file a path ->
port string ->
read all available data from port and write it to a file specified by path
procedure: port->lines a ->
port -> (string ...)
read all lines from port and return them as strings in a list
procedure: port->port a b [buffer-size] ->
procedure: port->string port ->
procedure: port-copy-all a b [buffer-size] ->
procedure: port-copy-some port port-2 count ->
port port integer ->
copy
procedure: port-lines-each proc #:handle-delim [port] ->
procedure:{line ->} port symbol ->
call proc once with every line read from a port
procedure: port-lines-fold proc init [port] ->
procedure:{string:line any} any [port] -> any
fold over lines read from port
procedure: port-lines-map proc [port] ->
procedure:{string:line -> any} [port] -> list
map each line of port to a list.
port is the current input port by default
procedure: port-lines-map->port proc #:handle-delim [port-input port-output] ->
procedure:{line -> line} [port port symbol:concat/trim/peek/split] -> unspecified
map lines from port to port. the trailing newline is included by default but this behaviour can be set like for read-line.
the default ports are the current input and output ports
procedure: read-until-string-proc strings ... ->
string ... -> procedure:{port -> (string:before-string . matched-string)}
returns a procedure that reads from a port until one of the given strings has been found
procedure: rw-port->port read write port port-2 ->
copied from io read-write to avoid circular dependency
procedure: socket-address-string->protocol-family a ->
string -> integer
procedure: socket-create-bound address #:port #:type #:protocol #:non-blocking #:set-options ->
string [integer integer integer] -> socket
create a socket, bind, and result in the socket object.
defaults
if address is a path starting with / then a local unix socket is created (no port necessary)
if address contains : then an ip6 tcp socket is created
else an ip4 tcp socket is created
procedure: socket-protocol-family->address-family a ->
integer -> integer
variable: sph-io-description
procedure: string->file a path ->
string string -> unspecified
write string into file at path, overwriting the file
procedure: temp-file-port [path name-part] ->
[string] [string:infix] -> port
create a new unique file in the file system and return a new buffered port for reading and writing to the file
procedure: temp-file-port->file proc path ->