equalfile

package module
Version: v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2018 License: MIT Imports: 6 Imported by: 8

README

GoDoc Go Report Card Travis Build Status Circle CI gocover

About Equalfile

Equalfile is a pure Go package for comparing files.

Install

Recipe with Modules (since Go 1.11)

Clone outside of GOPATH:

git clone https://github.com/udhos/equalfile
cd equalfile

Run tests:

go test

Install example application 'equal':

go install ./equal

Run example application:

~/go/bin/equal

Recipe without Modules (before Go 1.11)

Set up GOPATH as usual:

export GOPATH=$HOME/go
mkdir $GOPATH

Get equalfile package:

go get github.com/udhos/equalfile

Install example application 'equal':

go install github.com/udhos/equalfile/equal

Run example application:

$GOPATH/bin/equal

Usage

Add the import path:

import "github.com/udhos/equalfile"

See: equalfile GoDoc API

Example Application

See example application: equal source code

Documentation

Overview

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")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmp

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

func New

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

New creates Cmp for single comparison mode.

func NewMultiple

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

New creates Cmp for multiple comparison mode.

func (*Cmp) CompareFile

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

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

func (*Cmp) CompareReader

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

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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