fileinput

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2019 License: BSD-3-Clause Imports: 5 Imported by: 0

README

fileinput

http://godoc.org/github.com/creachadair/fileinput

The fileinput package implements utility functions for building command-line tools and interacting with subprocesses.

Documentation

Overview

Package fileinput provides utility functions for handling files named on the command line.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cat

func Cat(ctx context.Context, paths []string) io.ReadCloser

Cat returns an io.ReadCloser that delivers the logical concatenation of the specified input files. The files are read sequentially, and any non-nil, non-EOF error from one of the underlying files is returned. If no files are specified, the resulting reader is empty.

func CatOrFile

func CatOrFile(ctx context.Context, paths []string, f io.ReadCloser) io.ReadCloser

CatOrFile acts as Cat, but if no paths are specified it returns f.

func Each

func Each(ctx context.Context, paths []string, rf ReadFunc) error

Each opens each specified path for reading in the order given, passes its reader to rf, and closes the file when f returns.

If there is an error opening a file it is passed to rf. If rf reports an error, Each stops processing and returns that error.

func EachOrStdin

func EachOrStdin(ctx context.Context, paths []string, rf ReadFunc) error

EachOrStdin acts as Each, but if no paths are specified rf is called on os.Stdin instead.

Types

type Opener

type Opener func(context.Context, string) (io.ReadCloser, error)

An Opener function opens a file path for reading.

var Open Opener = osOpener

Open is used to open files for reading. The default implementation delegates to the os.Open function.

type ReadFunc

type ReadFunc func(r io.Reader, err error) error

A ReadFunc receives an open io.Reader or an error for processing. If err != nil, the value of r is unspecified.

Jump to

Keyboard shortcuts

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