fs

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package fs ships the file-system stream source and operators: fs.walk as a source; fs.filter, fs.read, fs.sort, fs.write, and the terminal sinks out.stdout and out.file as stream operators.

The pipeline carries fs.FileMeta between stages; fs.read replaces it with fs.FileContent (metadata + bytes) so downstream stages can inspect and transform file bodies.

Typical use:

fs.walk:ext="go" -> fs.filter:tests=true -> fs.read -> fs.sort:by="size" -> collect

Index

Constants

View Source
const ID = "fs"

Variables

View Source
var BinaryExtensions = map[string]bool{
	".exe": true, ".dll": true, ".so": true, ".dylib": true,
	".bin": true, ".obj": true, ".o": true, ".a": true,
	".png": true, ".jpg": true, ".jpeg": true, ".gif": true,
	".ico": true, ".webp": true, ".pdf": true,
	".zip": true, ".tar": true, ".gz": true, ".7z": true,
	".db": true, ".sqlite": true, ".sqlite3": true,
	".pyc": true, ".pyo": true, ".wasm": true,
}
View Source
var DefaultSkipDirs = []string{
	".git", "node_modules", "vendor", "target", "dist", "build",
	"_srcpack", ".next", ".turbo", ".cache", ".idea", ".vscode",
}

Functions

func Bundle

func Bundle(_ map[string]string) core.Bundle

func Filter

Filter returns a stream operator that drops files matching any of the configured exclusion rules.

func FilterOperator

func FilterOperator() action.NamedOperator

func GenerateStatsSummary

func GenerateStatsSummary(entries []StatEntry, maxDepth int) string

func Library

func Library() action.Library

func OutFile

func OutFile[T any](cfg OutFileConfig) action.StreamOp[T, T]

OutFile aggregates the whole stream into a single file. Content items (FileContent) are written byte-for-byte; everything else uses fmt.Sprint or Stringer.

func OutFileOperator

func OutFileOperator() action.NamedOperator

func Read

Read returns a stream operator that loads each file's bytes (or a selected subset of lines) into FileContent.

func ReadOperator

func ReadOperator() action.NamedOperator

func Sort

Sort buffers the stream and yields items in sorted order. Sorting is stable within equal keys.

func SortOperator

func SortOperator() action.NamedOperator

func Stdout

func Stdout(up iter.Seq2[FileMeta, error]) iter.Seq2[FileMeta, error]

Stdout prints each file's RelPath to stdout and passes the item through. It is the file-listing sink for `fs.walk -> out.stdout`.

func StdoutOperator

func StdoutOperator() action.NamedOperator

func WalkSource

func WalkSource() action.AnyStreamAction

func Write

Write persists each FileContent under Dir, preserving RelPath. It is the per-item counterpart to out.file, which aggregates the whole stream into one file.

RelPath is validated through xfs.Rel so a hostile upstream cannot escape Dir with ../ or absolute paths.

func WriteOperator

func WriteOperator() action.NamedOperator

Types

type FileContent

type FileContent struct {
	FileMeta
	Content []byte
}

FileContent is FileMeta plus the file body. fs.read replaces the stream item type from FileMeta to FileContent.

type FileMeta

type FileMeta struct {
	Path    string    `json:"path"`
	RelPath string    `json:"rel_path"`
	Size    int64     `json:"size"`
	ModTime time.Time `json:"mod_time"`
	Lang    string    `json:"lang"`
}

FileMeta is the item type that flows through the fs pipeline.

type FilterConfig

type FilterConfig struct {
	Ext       string `json:"ext" cli:"ext"`
	Tests     bool   `json:"tests"`
	Generated bool   `json:"generated"`
	Deps      bool   `json:"deps"`
	Examples  bool   `json:"examples"`
	Exclude   string `json:"exclude"`
}

FilterConfig controls fs.filter. All fields are optional; the zero value passes every file through.

type OutFileConfig

type OutFileConfig struct {
	Path      string `json:"path"       cli:"o,output"`
	Append    bool   `json:"append"     cli:"append"`
	FlushEach bool   `json:"flush_each"`
}

OutFileConfig controls out.file.

type ReadConfig

type ReadConfig struct {
	// Lines restricts the content to line ranges. Accepted forms:
	//
	//	"10"       single line
	//	"10-20"    inclusive range
	//	"10-"      from line 10 to end
	//	"1,3,5-7"  union of ranges
	//
	// Empty means the whole file.
	Lines string `json:"lines" cli:"lines"`
}

ReadConfig controls fs.read.

type SortConfig

type SortConfig struct {
	// By is one of "rel_path" (default), "size", "mod_time".
	By string `json:"by" cli:"by"`
	// MaxItems bounds the buffer. Zero uses a safe default of 100000.
	MaxItems int `json:"max_items" cli:"max_items"`
}

SortConfig controls fs.sort.

type StatEntry

type StatEntry struct {
	RelPath   string
	Size      int64
	FuncCount int
}

type WalkConfig

type WalkConfig struct {
	Dir           string   `json:"dir" cli:"dir,d"`
	Dirs          []string `json:"dirs" cli:"dirs"`
	Files         []string `json:"files" cli:"files,file,f"`
	Skip          []string `json:"skip" cli:"skip"`
	IncludeHidden bool     `json:"include_hidden" cli:"include_hidden"`
	IncludeAll    bool     `json:"include_all" cli:"include_all"`
	Ext           string   `json:"ext" cli:"ext"`
	MaxDepth      int      `json:"max_depth" cli:"max_depth"`
}

type WriteConfig

type WriteConfig struct {
	Dir       string `json:"dir"       cli:"dir,d"`
	Mode      uint32 `json:"mode"      cli:"mode"`
	Overwrite bool   `json:"overwrite" cli:"overwrite"`
}

WriteConfig controls fs.write.

Jump to

Keyboard shortcuts

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