2017-09-29

(sph io one)

port and file input/output.

library description

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

import name

(sph io one)

exports

bytevector->file

procedure

signature

a path ->

call-with-input-files

procedure

signature

proc paths ... ->

call-with-pipe

procedure

signature

proc ->

description

equivalent to (call-with-pipes 1 proc)

call-with-pipes

procedure

signature

count proc ->

integer procedure:{[pipe-n-in pipe-n-out] ... -> any} -> any

description

the pipes are not automatically closed.

reading from the input side might block as long as the output side is not yet closed

call-with-temp-file

procedure

signature

proc [path name-part] ->

procedure:{port -> any} -> any

description

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

each-u8

procedure

signature

proc port ->

procedure:{integer -> any} port -> unspecified

description

call proc with each eight bit integer read from port until end-of-file is reached.

file->bytevector

procedure

signature

path\file ->

string -> bytevector

description

open or use an opened file, read until end-of-file is reached and return a bytevector of file contents

file->file

procedure

signature

path-input path-output #:copy #:input-binary #:output-binary #:append? ->

string string procedure:{port port -> any} [#:input-binary boolean #:output-binary? boolean] -> any

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.

the ports are closed when copy returns

file->port

procedure

signature

path port ->

string port ->

description

copy all content of file at path to port

file->string

procedure

signature

path/file ->

string/file -> string

description

open or use an opened file, read until end-of-file is reached and return a string of file contents

files->port

procedure

signature

paths output ->

(string ...) port ->

named-pipe

procedure

signature

[path permissions] ->

[string integer] -> string:path

description

create a named pipe (fifo).

named pipes persist in the filesystem

named-pipe-chain

procedure

signature

first-input last-output proc ... ->

port/true port/true procedure:{pipe-input pipe-output -> false/any} ... -> (procedure-result ...)

description

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

pipe-chain

procedure

signature

first-input last-output proc ... ->

port/true port/true procedure:{pipe-input pipe-output -> false/any} ... -> (procedure-result ...)

description

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

port->bytevector

procedure

signature

a ->

port->file

procedure

signature

a path ->

port string ->

description

read all available data from port and write it to a file specified by path

port->lines

procedure

signature

a ->

port -> (string ...)

description

read all lines from port and return them as strings in a list

port->string

procedure

signature

port ->

port-copy-all

procedure

signature

a b [buffer-size] ->

port-copy-some

procedure

signature

port port-2 count ->

port port integer ->

description

copy "count" number of bytes from "port" to "port-2"

port-lines-each

procedure

signature

proc #:handle-delim [port] ->

procedure:{line ->} port symbol ->

description

call proc once with every line read from a port

port-lines-fold

procedure

signature

proc init [port] ->

description

procedure:{string:line any} any [port] -> any

fold over lines read from port

port-lines-map

procedure

signature

proc [port] ->

procedure:{string:line -> any} [port] -> list

description

map each line of port to a list.

port is the current input port by default

port-lines-map->port

procedure

signature

proc #:handle-delim [port-input port-output] ->

procedure [port port symbol:concat/trim/peek/split] ->

description

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

read-until-string-proc

procedure

signature

strings ... ->

string ... -> procedure:{port -> (string:before-string . matched-string)}

description

returns a procedure that reads from a port until one of the given strings has been found

socket-address-string->protocol-family

procedure

signature

a ->

string -> integer

socket-create-bound

procedure

signature

address #:port #:type #:protocol #:non-blocking #:set-options ->

string [integer integer integer] -> socket

description

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

socket-protocol-family->address-family

procedure

signature

a ->

integer -> integer

string->file

procedure

signature

a path ->

string string -> unspecified

description

write string into file at path, overwriting the file

temp-file-port

procedure

signature

[path name-part] ->

[string] [string:infix] -> port

description

create a new unique file in the file system and return a new buffered port for reading and writing to the file

temp-file-port->file

procedure

signature

proc path ->


tags: guile documentation library scheme sph-lib computer sph-io-one