fs

package
v0.0.0-...-ebf99ae Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List struct {
	Root string

	Recursive    bool
	ShowHidden   bool
	IncludeDirs  bool
	ExcludeFiles bool
}

List is a pipe/line producer/transformer to list the files/folders in a folder

func (List) P

func (l List) P(out chan<- interface{}, errs chan<- error)

P is the producer

Example
package main

import (
	"github.com/MasteryConnect/pipe/extras/fs"
	"github.com/MasteryConnect/pipe/line"
	"github.com/MasteryConnect/pipe/message"
	"github.com/MasteryConnect/pipe/x"
)

func main() {
	line.New().SetP(
		fs.List{
			Root:         "/",
			IncludeDirs:  true,
			ExcludeFiles: true,
			Recursive:    false,
		}.P,
	).Add(
		line.I(func(m interface{}) (interface{}, error) {
			msg := m.(message.FileInfo)
			if msg.IsDir() {
				return "**dir**", nil
			}
			return m, nil
		}),
		x.Head{N: 1}.T, // limit the list to just 1 for output testing
		line.Stdout,
	).Run()

}
Output:

**dir**

func (List) T

func (l List) T(in <-chan interface{}, out chan<- interface{}, errs chan<- error)

T is the Tfunc for a pipe/line.

type Read

type Read struct {
	Path             string
	MaxScanTokenSize int
}

Read will read the messages from a file much like from stdin.

func (Read) P

func (r Read) P(out chan<- interface{}, errs chan<- error)

P is the producer

func (Read) T

func (r Read) T(in <-chan interface{}, out chan<- interface{}, errs chan<- error)

T is the Tfunc for a pipe/line.

type Write

type Write struct {
	Path    string
	Prefix  string // add to the beginning of each message
	Postfix string // add to the end of each message (useful for adding newlines at the end)
}

Write will write the messages to a file much like to stdout.

func (Write) T

func (w Write) T(in <-chan interface{}, out chan<- interface{}, errs chan<- error)

T is the Tfunc for a pipe/line.

Jump to

Keyboard shortcuts

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