equalfile: github.com/udhos/equalfile Index | Files | Directories

package equalfile

import "github.com/udhos/equalfile"

Package equalfile provides facilities for comparing files.

Equalfile is similar to Python's filecmp:

import filecmp
if filecmp.cmp(filename1, filename2, shallow=False):

Comparing only two files

In single mode, equalfile compares files byte-by-byte.

import "github.com/udhos/equalfile"
// ...
cmp := equalfile.New(nil, equalfile.Options{}) // compare using single mode
equal, err := cmp.CompareFile("file1", "file2")

Comparing multiple files

In multiple mode, equalfile records files hashes in order to speedup repeated comparisons. You must provide the hashing function.

import "crypto/sha256"
import "github.com/udhos/equalfile"
// ...
cmp := equalfile.NewMultiple(nil, equalfile.Options{}, sha256.New(), true) // enable multiple mode
equal, err := cmp.CompareFile("file1", "file2")


Package Files

doc.go equalfile.go

type Cmp Uses

type Cmp struct {
    Opt Options
    // contains filtered or unexported fields

func New Uses

func New(buf []byte, options Options) *Cmp

New creates Cmp for single comparison mode.

func NewMultiple Uses

func NewMultiple(buf []byte, options Options, h hash.Hash, compareOnMatch bool) *Cmp

New creates Cmp for multiple comparison mode.

func (*Cmp) CompareFile Uses

func (c *Cmp) CompareFile(path1, path2 string) (bool, error)

CompareFile verifies that files with names path1, path2 have same contents.

func (*Cmp) CompareReader Uses

func (c *Cmp) CompareReader(r1, r2 io.Reader) (bool, error)

CompareReader verifies that two readers provide same content.

Reading more than MaxSize will return an error (along with the comparison value up to MaxSize bytes), unless one or both Readers are LimitedReaders, in which case MaxSize is ignored.

type Options Uses

type Options struct {
    Debug         bool // enable debugging to stdout
    ForceFileRead bool // prevent shortcut at filesystem level (link, pathname, etc)

    // MaxSize is a safely limit to prevent forever reading from an infinite
    // reader.  If left unset, will default to 1OGBytes. Ignored when
    // CompareReader() is given one or more io.LimitedReader.
    MaxSize int64



Package equalfile imports 6 packages (graph) and is imported by 4 packages. Updated 2018-11-06. Refresh now. Tools for package owners.