uniquefile

package module
v0.0.0-...-a277187 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: AGPL-3.0 Imports: 13 Imported by: 0

README

uniquefile

Find unique files from various sources

Documentation

Index

Constants

View Source
const (
	FileScheme = "file"
)

Variables

View Source
var (
	// ErrCannotCmp is returned when an IndicatorCmper is asked
	// to compare values whose keys it doesn't recognize (e.g.
	// if you pass CRC32s to the LengthIndicator).
	ErrCannotCmp = errors.New("cannot compare values of these keys")
)
View Source
var LengthIndicator interface {
	Indicator
	IndicatorCmper
} = lengthIndicator{}

LengthIndicator determines the length of the Reader in bytes. The resulting length is written out in big endian ("network") byte order.

Functions

func PutIndication

func PutIndication(i **Indication)

PutIndication puts an Indication back into the cache so it can be reused.

Types

type Bytes

type Bytes string

Bytes is just a string but its separate type makes it clear that the data is unlikely to be UTF-8 text.

type Indication

type Indication struct {
	// contains filtered or unexported fields
}

Indication is a sequence of key and value byte slices.

func NewIndication

func NewIndication() *Indication

func (*Indication) Bytes

func (i *Indication) Bytes() []byte

Bytes accesses the byte representation of the indication directly.

func (*Indication) Each

func (i *Indication) Each(fn func(key, value []byte) error) error

func (*Indication) Lookup

func (i *Indication) Lookup() (IndicationLookup, error)

Lookup creates an IndicationLookup from an indication.

func (*Indication) Reader

func (i *Indication) Reader() (reader interface {
	Next() (key, value []byte, err error)
})

Reader creates a reader over the Indication that parses its keys and values out.

func (*Indication) Reset

func (i *Indication) Reset()

Reset the Indication so it can be re-written into. Do not call this while you have a reader over the indication.

func (*Indication) Write

func (i *Indication) Write(key, value []byte)

Write writes a key and value into the indication.

type IndicationLookup

type IndicationLookup map[Bytes][]byte

func (IndicationLookup) WriteToIndication

func (lu IndicationLookup) WriteToIndication(ind *Indication)

type Indicator

type Indicator interface {
	// Indicate reads the reader and appends into bs an indication
	// which can be used to identify the uniqueness of the data.
	Indicate(ctx context.Context, r io.Reader, ind *Indication) error
}

Indicator reads r and populates ind with one or more indications.

var CRC32Indicator Indicator = hashAndLengthIndicator{
	// contains filtered or unexported fields
}

CRC32Indicator computes the CRC32 of its data

var SHA256Indicator Indicator = hashAndLengthIndicator{
	// contains filtered or unexported fields
}

SHA256Indicator computes the SHA-256 of its data

func NewIndicators

func NewIndicators(irs ...Indicator) Indicator

func ParseIndicator

func ParseIndicator(s string) (Indicator, bool)

ParseIndicator parses an indicator by its key

type IndicatorCmper

type IndicatorCmper interface {
	// Keys returns the keys that this IndicatorCmper can compare
	Keys() []Bytes

	// Cmp compares values from an indicator.
	Cmp(ctx context.Context, key, a, b []byte) (int, error)
}

IndicatorCmper can be implemented by Indicators to compare indications it produced. What that means depends on the indicator. For example, the LengthIndicator's Cmp compares the lengths (longer compares greater than lower).

type Indicators

type Indicators struct {
	// contains filtered or unexported fields
}

func (*Indicators) Close

func (irs *Indicators) Close() error

func (*Indicators) Indicate

func (irs *Indicators) Indicate(ctx context.Context, r io.Reader, ind *Indication) error

type Repo

type Repo interface {
	// Indications retrieves the indication(s) associated with the
	// given URI (if any).
	Indications(ctx context.Context, u URI) (*Indication, error)

	// SetIndications adds (or replaces) the URI's indications with
	// those provided.
	SetIndications(ctx context.Context, u URI, ind *Indication) error

	// URIs returns zero or more URIs that match the queried
	// Indications.  query can be a single indication or any
	// hierarchy of expr.And or expr.Or expressions whose leaves
	// are Indications.
	URIs(ctx context.Context, query expr.Expr) ([]URI, error)
}

type URI

type URI struct {
	Scheme   string
	Hostname string
	Path     string
	Query    string
}

URI defines a resource that can be queried to obtain its indicators.

func (*URI) FromString

func (u *URI) FromString(s string) error

func (*URI) FromURL

func (u *URI) FromURL(ur *url.URL)

func (*URI) String

func (u *URI) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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