wdte: github.com/DeedleFake/wdte/std/io Index | Files | Directories

package io

import "github.com/DeedleFake/wdte/std/io"

Package io contains WDTE functions for dealing with files and other types of data streams.

Index

Package Files

io.go

Variables

var (
    Stdin  io.Reader = os.Stdin
    Stdout io.Writer = os.Stdout
    Stderr io.Writer = os.Stderr
)

These variables are what are returned by the corresponding functions in this package. If a client wants to globally redirect input or output, they may simply change these variables.

var Scope = wdte.S().Map(map[wdte.ID]wdte.Func{
    "stdin":  stdin{},
    "stdout": stdout{},
    "stderr": stderr{},

    "seek":  wdte.GoFunc(Seek),
    "close": wdte.GoFunc(Close),

    "combine": wdte.GoFunc(Combine),
    "copy":    wdte.GoFunc(Copy),

    "string": wdte.GoFunc(String),
    "lines":  wdte.GoFunc(Lines),
    "words":  wdte.GoFunc(Words),
    "scan":   wdte.GoFunc(Scan),
    "runes":  wdte.GoFunc(Runes),

    "write":   wdte.GoFunc(Write),
    "writeln": wdte.GoFunc(Writeln),
    "panic":   wdte.GoFunc(Panic),
})

Scope is a scope containing the functions in this package.

func Close Uses

func Close(frame wdte.Frame, args ...wdte.Func) wdte.Func

Close is a WDTE function with the following signatures:

close c

Returns c after closing it.

func Combine Uses

func Combine(frame wdte.Frame, args ...wdte.Func) wdte.Func

Combine is a WDTE function with the following signatures:

combine a ...
(combine a) ...

If the arguments passed are readers, it returns a reader that reads each until EOF before continuing to the next, and finally yielding EOF itself when the last reader does.

If the arguments passed are writers, it returns a writer that writes each write to all of them in turn, only returning when they have all returned.

func Copy Uses

func Copy(frame wdte.Frame, args ...wdte.Func) wdte.Func

Copy is a WDTE function with the following signatures:

copy w r
(copy w) r
copy r w
(copy r) w

Copies from the reader r into the writer w until r yields EOF. Returns whichever argument was given second.

The reason for this return discrepency is to allow both variants of the function to be used more easily in chains. For example, both of the following work:

stdout -> copy stdin -> ... # Later elements will be given stdout.
stdin -> copy stdout -> ... # Later elements will be given stdin.

func Lines Uses

func Lines(frame wdte.Frame, args ...wdte.Func) wdte.Func

Lines is a WDTE function with the following signature:

lines r

Returns a stream.Stream that yields, as strings, successive lines read from the reader r.

func Panic Uses

func Panic(frame wdte.Frame, args ...wdte.Func) wdte.Func

Panic is a WDTE function with the following signatures:

panic err
panic w err
panic desc err
panic w desc err

Note that, somewhat unusually, Panic accepts its arguments in any order.

It writes the given error to w, prepending the optional description in the form `desc: err` and appending a newline. It then returns the error. If an error occurs somewhere internally, such as while printing, that error is returned instead.

If w is not given, it defaults to Stderr.

Panic is primarily intended for use with the error chain operator. For example:

+ a b -| panic 'Failed to add a and b';

func Runes Uses

func Runes(frame wdte.Frame, args ...wdte.Func) wdte.Func

Runes is a WDTE function with the following signature:

runes r

Returns a stream.Stream that yields individual Unicode characters from the reader r as numbers.

TODO: Maybe it makes more sense for them to be yielded as strings with a length of one.

func Scan Uses

func Scan(frame wdte.Frame, args ...wdte.Func) wdte.Func

Scan is a WDTE function with the following signatures:

scan r sep
(scan r) sep
scan sep r
(scan sep) r

Returns a stream.Stream that yields sections of the reader r split around the separator string sep. For example,

readString 'this--is--an--example' -> scan '--'

will return a stream.Stream that will yield 'this', 'is', 'an', and 'example'.

func Seek Uses

func Seek(frame wdte.Frame, args ...wdte.Func) wdte.Func

Seek is a WDTE function with the following signatures:

seek s n w
(seek w) s n
(seek n w) s

Returns s after seeking s to n, with a relative position denoted by w:

If w is greater than 0, it seeks relative to the beginning of s.

If w is equal to 0, it seeks relative to the current location in s.

If w is less than 0, it seeks relative to the end of s.

func String Uses

func String(frame wdte.Frame, args ...wdte.Func) wdte.Func

String is a WDTE function with the following signature:

string r

Reads the entirety of the reader r and returns the result as a string.

func Words Uses

func Words(frame wdte.Frame, args ...wdte.Func) wdte.Func

Words is a WDTE function with the following signature:

words r

Returns a stream.Stream that yields, as strings, successive words read from the reader r.

func Write Uses

func Write(frame wdte.Frame, args ...wdte.Func) wdte.Func

Write is a WDTE function with the following signatures:

write w d
(write w) d
write d w
(write d) w

It writes the data d to the writer w in much the same way that Go's fmt.Fprint does. It returns w to allow for easier chaining.

If both arguments are writers, it will consider either the first argument or the outer argument to be w.

func Writeln Uses

func Writeln(frame wdte.Frame, args ...wdte.Func) wdte.Func

Writeln is a WDTE function with the following signatures:

writeln w d
(writeln w) d
writeln d w
(writeln d) w

It writes the data d to the writer w in much the same way that Go's fmt.Fprintln does. It returns w to allow for easier chaining.

If both arguments are writers, it will consider either the first argument or the outer argument to be w.

type Reader Uses

type Reader struct {
    io.Reader
}

Reader wraps an io.Reader, allowing it to be used as a WDTE function.

Note that using this specific type is not necessary. Any wdte.Func that implements io.Reader is also accepted by the functions in this module.

func (Reader) Call Uses

func (r Reader) Call(frame wdte.Frame, args ...wdte.Func) wdte.Func

func (Reader) Reflect Uses

func (r Reader) Reflect(name string) bool

func (Reader) String Uses

func (r Reader) String() string

type Writer Uses

type Writer struct {
    io.Writer
}

Writer wraps an io.Writer, allowing it to be used as a WDTE function.

Note that using this specific type is not necessary. Any wdte.Func that implements io.Writer is also accepted by the functions in this module.

func (Writer) Call Uses

func (w Writer) Call(frame wdte.Frame, args ...wdte.Func) wdte.Func

func (Writer) Reflect Uses

func (w Writer) Reflect(name string) bool

func (Writer) String Uses

func (w Writer) String() string

Directories

PathSynopsis
filePackage file provides functions for dealing with files.

Package io imports 8 packages (graph) and is imported by 1 packages. Updated 2019-07-21. Refresh now. Tools for package owners.