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