diff

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package diff compares two CSV files as tables rather than as text.

The comparison runs in two passes. The first pass walks the old file and records, for every row, its key, a 128-bit fingerprint of the compared columns, and the byte offset where the row starts. The second pass streams the new file and looks each row up in that index. Full row text is only ever pulled back off disk for rows that turn out to differ, so memory grows with the number of rows rather than with the width of the file.

Index

Constants

View Source
const (
	KeyExplicit = "explicit"
	KeyAuto     = "auto-detected"
	KeyFullRow  = "full-row"
)

How the matching key was chosen.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	Column string `json:"column"`
	Old    string `json:"old"`
	New    string `json:"new"`
}

Change is one differing cell within a modified row.

type FileInfo

type FileInfo struct {
	Name      string `json:"name"`
	Encoding  string `json:"encoding"`
	Delimiter string `json:"delimiter"`
	Rows      int    `json:"rows"`
}

FileInfo describes one side of the comparison.

type Modified

type Modified struct {
	Key     string
	Old     Row
	New     Row
	Changes []Change
}

Modified is a row that matched by key but whose compared values differ.

type Moved

type Moved struct {
	Key         string
	OldPosition int
	NewPosition int
	Values      []string
}

Moved is a row whose content is identical but whose position shifted. The values are re-read from the old file so that exports carry the whole row rather than just a key.

type Options

type Options struct {
	Key           []string // explicit key columns; empty means decide automatically
	FullRow       bool     // force whole-row matching, skipping key detection
	IgnoreColumns []string // columns excluded from the comparison
	Strict        bool     // compare values byte for byte and treat column order as significant
	NoHeader      bool     // treat the first row as data and name columns c1, c2, ...
	ShowReordered bool     // report rows whose content is unchanged but whose position moved
}

Options controls how two files are matched and compared.

type Result

type Result struct {
	Old, New FileInfo

	Columns        []string // union of both headers, in display order
	Compared       []string // columns actually used for the comparison
	Ignored        []string
	AddedColumns   []string
	RemovedColumns []string
	OrderChanged   bool

	Key       []string
	KeySource string

	Added     []Row
	Removed   []Row
	Modified  []Modified
	Moved     []Moved
	Unchanged int

	Warnings []string
}

Result is the full comparison.

func Compute

func Compute(oldSrc, newSrc *csvsrc.Source, opt Options) (*Result, error)

Compute compares two opened sources.

func (*Result) HasChanges

func (r *Result) HasChanges() bool

HasChanges reports whether anything the caller asked about actually differs.

type Row

type Row struct {
	Key      string
	Values   []string
	Position int
	Line     int
}

Row is a single record, with its values aligned to Result.Columns.

Jump to

Keyboard shortcuts

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