io

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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),

	"readString": wdte.GoFunc(ReadString),
	"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),
})

Scope is a scope containing the functions in this package.

Functions

func Close

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

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

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

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 ReadString

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

ReadString is a WDTE function with the following signature:

readString s

Returns a reader which reads from the string s.

func Runes

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

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

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

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

String is a WDTE function with the following signature:

strings r

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

func Words

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

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

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.

Types

type Reader

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

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

func (Reader) String added in v0.2.3

func (r Reader) String() string

type Writer

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

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

func (Writer) String added in v0.2.3

func (w Writer) String() string

Directories

Path Synopsis
Package file provides functions for dealing with files.
Package file provides functions for dealing with files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL