{"modulePath":"github.com/github/git-sizer","version":"v1.5.0","isLatest":false,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package pipe\n\n## Variables\n\n```go\nvar (\n\t// IsSIGPIPE is an `ErrorMatcher` that matches `*exec.ExitError`s\n\t// that were caused by SIGPIPE. The match for `*exec.ExitError`s\n\t// uses `errors.As()`. Use like\n\t//\n\t//     p.Add(IgnoreError(someStage, IsSIGPIPE))\n\tIsSIGPIPE = IsSignal(syscall.SIGPIPE)\n\n\t// IsEPIPE is an `ErrorMatcher` that matches `syscall.EPIPE` using\n\t// `errors.Is()`. Use like\n\t//\n\t//     p.Add(IgnoreError(someStage, IsEPIPE))\n\tIsEPIPE = IsError(syscall.EPIPE)\n\n\t// IsErrClosedPipe is an `ErrorMatcher` that matches\n\t// `io.ErrClosedPipe` using `errors.Is()`. (`io.ErrClosedPipe` is\n\t// the error that results from writing to a closed\n\t// `*io.PipeWriter`.) Use like\n\t//\n\t//     p.Add(IgnoreError(someStage, IsErrClosedPipe))\n\tIsErrClosedPipe = IsError(io.ErrClosedPipe)\n\n\t// IsPipeError is an `ErrorMatcher` that matches a few different\n\t// errors that typically result if a stage writes to a subsequent\n\t// stage that has stopped reading from its stdin. Use like\n\t//\n\t//     p.Add(IgnoreError(someStage, IsPipeError))\n\tIsPipeError = AnyError(IsSIGPIPE, IsEPIPE, IsErrClosedPipe)\n)\n```\n\n```go\nvar FinishEarly = errors.New(\"finish stage early\")\n```\nFinishEarly is an error that can be returned by a \\`Stage\\` to request that the iteration be ended early (possibly without reading all of its input). This \"error\" is considered a successful return, and is not reported to the caller.\n\n## Functions\n\n```go\nfunc ScanLFTerminatedLines(data []byte, atEOF bool) (advance int, token []byte, err error)\n```\nScanLFTerminatedLines is a \\`bufio.SplitFunc\\` that splits its input into lines at LF characters (not treating CR specially).\n\n## Types\n\n```go\ntype Env struct {\n\t// The directory in which external commands should be executed by\n\t// default.\n\tDir string\n}\n```\nEnv represents the environment that a pipeline stage should run in. It is passed to \\`Stage.Start()\\`.\n\n```go\ntype ErrorFilter func(err error) error\n```\nErrorFilter is a function that can filter errors from \\`Stage.Wait()\\`. The original error (possibly nil) is passed in as an argument, and whatever the function returns is the error (possibly nil) that is actually emitted.\n\n```go\ntype ErrorMatcher func(err error) bool\n```\nErrorMatcher decides whether its argument matches some class of errors (e.g., errors that we want to ignore). The function will only be invoked for non-nil errors.\n\n```go\nfunc AnyError(ems ...ErrorMatcher) ErrorMatcher\n```\nAnyError returns an \\`ErrorMatcher\\` that returns true for an error that matches any of the \\`ems\\`.\n\n```go\nfunc IsError(target error) ErrorMatcher\n```\nIsError returns an ErrorIdentifier for the specified target error, matched using \\`errors.Is()\\`. Use like\n\n\tp.Add(pipe.IgnoreError(someStage, IsError(io.EOF)))\n\n```go\nfunc IsSignal(signal syscall.Signal) ErrorMatcher\n```\nIsSIGPIPE returns an \\`ErrorMatcher\\` that matches \\`\\*exec.ExitError\\`s that were caused by the specified signal. The match for \\`\\*exec.ExitError\\`s uses \\`errors.As()\\`. Note that under Windows this always returns false, because on that platform \\`WaitStatus.Signaled()\\` isn't implemented (it is hardcoded to return \\`false\\`).\n\n```go\ntype LinewiseStageFunc func(\n\tctx context.Context, env Env, line []byte, stdout *bufio.Writer,\n) error\n```\nLinewiseStageFunc is a function that can be embedded in a \\`goStage\\`. It is called once per line in the input (where \"line\" can be defined via any \\`bufio.Scanner\\`). It should process the line and may write whatever it likes to \\`stdout\\`, which is a buffered writer whose contents are forwarded to the input of the next stage of the pipeline. The function needn't write one line of output per line of input.\n\nThe function mustn't retain copies of \\`line\\`, since it may be overwritten every time the function is called.\n\nThe function needn't flush or close \\`stdout\\` (this will be done automatically when all of the input has been processed).\n\nIf there is an error parsing the input into lines, or if this function returns an error, then the whole pipeline will be aborted with that error. However, if the function returns the special error \\`pipe.FinishEarly\\`, the stage will stop processing immediately with a \\`nil\\` error value.\n\nThe function will be called in a separate goroutine, so it must be careful to synchronize any data access aside from writing to \\`stdout\\`.\n\n```go\ntype NewScannerFunc func(r io.Reader) (Scanner, error)\n```\nNewScannerFunc is used to create a \\`Scanner\\` for scanning input that is coming from \\`r\\`.\n\n```go\ntype Option func(*Pipeline)\n```\nOption is a type alias for Pipeline functional options.\n\n```go\nfunc WithDir(dir string) Option\n```\nWithDir sets the default directory for running external commands.\n\n```go\nfunc WithStdin(stdin io.Reader) Option\n```\nWithStdin assigns stdin to the first command in the pipeline.\n\n```go\nfunc WithStdout(stdout io.Writer) Option\n```\nWithStdout assigns stdout to the last command in the pipeline.\n\n```go\nfunc WithStdoutCloser(stdout io.WriteCloser) Option\n```\nWithStdoutCloser assigns stdout to the last command in the pipeline, and closes stdout when it's done.\n\n```go\ntype Pipeline struct {\n\t// contains filtered or unexported fields\n}\n```\nPipeline represents a Unix-like pipe that can include multiple stages, including external processes but also and stages written in Go.\n\n```go\nfunc New(options ...Option) *Pipeline\n```\nNewPipeline returns a Pipeline struct with all of the \\`options\\` applied.\n\n```go\nfunc (p *Pipeline) Add(stages ...Stage)\n```\nAdd appends one or more stages to the pipeline.\n\n```go\nfunc (p *Pipeline) AddWithIgnoredError(em ErrorMatcher, stages ...Stage)\n```\nAddWithIgnoredError appends one or more stages that are ignoring the passed in error to the pipeline.\n\n```go\nfunc (p *Pipeline) Output(ctx context.Context) ([]byte, error)\n```\n\n```go\nfunc (p *Pipeline) Run(ctx context.Context) error\n```\nRun starts and waits for the commands in the pipeline.\n\n```go\nfunc (p *Pipeline) Start(ctx context.Context) error\n```\nStart starts the commands in the pipeline. If \\`Start()\\` exits without an error, \\`Wait()\\` must also be called, to allow all resources to be freed.\n\n```go\nfunc (p *Pipeline) Wait() error\n```\nWait waits for each stage in the pipeline to exit.\n\n```go\ntype Scanner interface {\n\tScan() bool\n\tBytes() []byte\n\tErr() error\n}\n```\nScanner defines the interface (which is implemented by \\`bufio.Scanner\\`) that is needed by \\`AddScannerFunction()\\`. See \\`bufio.Scanner\\` for how these methods should behave.\n\n```go\ntype Stage interface {\n\t// Name returns the name of the stage.\n\tName() string\n\n\t// Start starts the stage in the background, in the environment\n\t// described by `env`, and using `stdin` as input. (`stdin` should\n\t// be set to `nil` if the stage is to receive no input, which\n\t// might be the case for the first stage in a pipeline.) It\n\t// returns an `io.ReadCloser` from which the stage's output can be\n\t// read (or `nil` if it generates no output, which should only be\n\t// the case for the last stage in a pipeline). It is the stages'\n\t// responsibility to close `stdin` (if it is not nil) when it has\n\t// read all of the input that it needs, and to close the write end\n\t// of its output reader when it is done, as that is generally how\n\t// the subsequent stage knows that it has received all of its\n\t// input and can finish its work, too.\n\t//\n\t// If `Start()` returns without an error, `Wait()` must also be\n\t// called, to allow all resources to be freed.\n\tStart(ctx context.Context, env Env, stdin io.ReadCloser) (io.ReadCloser, error)\n\n\t// Wait waits for the stage to be done, either because it has\n\t// finished or because it has been killed due to the expiration of\n\t// the context passed to `Start()`.\n\tWait() error\n}\n```\nStage is an element of a \\`Pipeline\\`.\n\n```go\nfunc Command(command string, args ...string) Stage\n```\nCommand returns a pipeline \\`Stage\\` based on the specified external \\`command\\`, run with the given command-line \\`args\\`. Its stdin and stdout are handled as usual, and its stderr is collected and included in any \\`\\*exec.ExitError\\` that the command might emit.\n\n```go\nfunc CommandStage(name string, cmd *exec.Cmd) Stage\n```\nCommand returns a pipeline \\`Stage\\` with the name \\`name\\`, based on the specified \\`cmd\\`. Its stdin and stdout are handled as usual, and its stderr is collected and included in any \\`\\*exec.ExitError\\` that the command might emit.\n\n```go\nfunc FilterError(s Stage, filter ErrorFilter) Stage\n```\n\n```go\nfunc Function(name string, f StageFunc) Stage\n```\nFunction returns a pipeline \\`Stage\\` that will run a \\`StageFunc\\` in a separate goroutine to process the data. See \\`StageFunc\\` for more information.\n\n```go\nfunc IgnoreError(s Stage, em ErrorMatcher) Stage\n```\nIgnoreError creates a stage that acts like \\`s\\` except that it ignores any errors that are matched by \\`em\\`. Use like\n\n\tp.Add(pipe.IgnoreError(\n\t    someStage,\n\t    func(err error) bool {\n\t        var myError *MyErrorType\n\t        return errors.As(err, \u0026myError) \u0026\u0026 myError.foo == 42\n\t    },\n\t)\n\nThe second argument can also be one of the \\`ErrorMatcher\\`s that are provided by this package (e.g., \\`IsError(target)\\`, IsSignal(signal), \\`IsSIGPIPE\\`, \\`IsEPIPE\\`, \\`IsPipeError\\`), or one of the functions from the standard library that has the same signature (e.g., \\`os.IsTimeout\\`), or some combination of these (e.g., \\`AnyError(IsSIGPIPE, os.IsTimeout)\\`).\n\n```go\nfunc LinewiseFunction(name string, f LinewiseStageFunc) Stage\n```\nLinewiseFunction returns a function-based \\`Stage\\`. The input will be split into LF-terminated lines and passed to the function one line at a time (without the LF). The function may emit output to its \\`stdout\\` argument. See the definition of \\`LinewiseStageFunc\\` for more information.\n\nNote that the stage will emit an error if any line (including its end-of-line terminator) exceeds 64 kiB in length. If this is too short, use \\`ScannerFunction()\\` directly with your own \\`NewScannerFunc\\` as argument, or use \\`Function()\\` directly with your own \\`StageFunc\\`.\n\n```go\nfunc Print(a ...interface{}) Stage\n```\n\n```go\nfunc Printf(format string, a ...interface{}) Stage\n```\n\n```go\nfunc Println(a ...interface{}) Stage\n```\n\n```go\nfunc ScannerFunction(\n\tname string, newScanner NewScannerFunc, f LinewiseStageFunc,\n) Stage\n```\nScannerFunction creates a function-based \\`Stage\\`. The function will be passed input, one line at a time, and may emit output. See the definition of \\`LinewiseStageFunc\\` for more information.\n\n```go\ntype StageFunc func(ctx context.Context, env Env, stdin io.Reader, stdout io.Writer) error\n```\nStageFunc is a function that can be used to power a \\`goStage\\`. It should read its input from \\`stdin\\` and write its output to \\`stdout\\`. \\`stdin\\` and \\`stdout\\` will be closed automatically (if necessary) once the function returns.\n\nNeither \\`stdin\\` nor \\`stdout\\` are necessarily buffered. If the \\`StageFunc\\` requires buffering, it needs to arrange that itself.\n\nA \\`StageFunc\\` is run in a separate goroutine, so it must be careful to synchronize any data access aside from reading and writing.\n\n","path":"github.com/github/git-sizer/internal/pipe","name":"pipe","synopsis":"","isRedistributable":true}
