sink

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWrite

func AtomicWrite(dst, src string) error

AtomicWrite moves src to dst atomically. It tries os.Rename first (same-filesystem fast path). On cross-filesystem moves, it copies src to a temp file in dst's directory and then renames to avoid partial writes.

func ExpandTemplate

func ExpandTemplate(tpl, stem, toFormat string, seq int) string

ExpandTemplate replaces placeholders in tpl:

{stem} — filename without extension
{to}   — target format ID
{date} — current date as YYYYMMDD
{seq}  — zero-padded 4-digit sequence number

Types

type Action

type Action int

Action is the resolved action after applying a conflict policy.

const (
	ActionWrite Action = iota
	ActionSkip
)

func Resolve

func Resolve(path string, policy ConflictPolicy) (string, Action, error)

Resolve returns the final output path and action given a potential conflict. If the file does not exist, it always returns (path, ActionWrite, nil).

type ConflictPolicy

type ConflictPolicy int

ConflictPolicy controls what happens when the output file already exists.

const (
	ConflictOverwrite ConflictPolicy = iota
	ConflictSkip
	ConflictRename
	ConflictError
)

func ParseConflictPolicy

func ParseConflictPolicy(s string) (ConflictPolicy, error)

ParseConflictPolicy parses a string policy name.

type Sink

type Sink struct {
	Type     SinkType
	Path     string         // empty for SinkTypeStdout
	Format   string         // canonical target format ID
	Policy   ConflictPolicy // how to handle existing files
	Template string         // optional naming template for SinkTypeDir
}

Sink describes where converted output is written.

func ResolveSink

func ResolveSink(output, toFormat string) *Sink

ResolveSink determines the sink type from the output path string.

  • "-" or empty → SinkTypeStdout
  • path ending in "/" or existing directory → SinkTypeDir
  • everything else → SinkTypeFile

type SinkType

type SinkType int

SinkType classifies the output destination.

const (
	SinkTypeFile   SinkType = iota // single output file
	SinkTypeDir                    // output directory (one file per input)
	SinkTypeStdout                 // write to stdout
)

Jump to

Keyboard shortcuts

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