codec

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2014 License: LGPL-3.0 Imports: 14 Imported by: 3

Documentation

Overview

Package codec provides support for serializing and deserializing file-hash information using channels.

Channel-based operation allows to stream file information, which becomes relevant when millions of files are supposed to be handled without any delay or noticeable memory overhead.

Index

Constants

View Source
const (
	GobName      = "gob"
	GobExtension = "gobz"
	Version      = 1
)
View Source
const (
	MHLName      = "mhl"
	MHLExtension = "mhl"
	MHLVersion   = "1.0"
)

Variables

This section is empty.

Functions

func Names added in v1.1.0

func Names() []string

Types

type Codec

type Codec interface {
	// Write the file-info structures received from in channel to the given writer.
	// When the channel is closed, the read-operation naturally finishes.
	// The codec must protect the written data against modification, usually by hashing the contained information
	Serialize(in <-chan api.FileInfo, writer io.Writer) error

	// Stream a FileInfo obtained from the given reader.
	// An error must be returned if the data read could not be verified.
	// You must pass each read fileinfo structure to the given predicate - it might modify it before
	// sending it down the channel. It returns false in case you should stop reading and return without error
	// Check the done-channel and cancel the operation
	// This function doesn't close the stream
	// The only errors returned must of type DecodeError
	Deserialize(reader io.Reader, out chan<- api.FileInfo, predicate func(*api.FileInfo) bool) error

	// Extension returns the file extension of the codec, without the '.' prefix
	Extension() string
}

Represents a codec's standard capabilities. A codec is a specialized implementation able to read and write indices of file hash information NOTE: Even though it would be more idiomatic to have two interfaces for read and write respectively, we just don't need it here

func NewByName added in v1.1.0

func NewByName(name string) Codec

Find a codec matching the given name, and return it. Retuns nil otherwise

func NewByPath

func NewByPath(path string) Codec

Finds a codec which can decode the file at the given path. We work strictly by name.

type DecodeError added in v1.1.0

type DecodeError struct {
	Msg string
}

func (*DecodeError) Error added in v1.1.0

func (d *DecodeError) Error() string

type Gob

type Gob struct {
}

Reads and writes a file structured like so - version - numEntries - gobValue... - sha1 (hash of all hashes in prior map)

func (*Gob) Deserialize

func (g *Gob) Deserialize(reader io.Reader, out chan<- api.FileInfo, predicate func(*api.FileInfo) bool) error

func (*Gob) Extension

func (g *Gob) Extension() string

func (*Gob) Serialize

func (g *Gob) Serialize(in <-chan api.FileInfo, writer io.Writer) (err error)

type MHL added in v1.1.0

type MHL struct {
}

Empty type to implement the codec interface

func (*MHL) Deserialize added in v1.1.0

func (m *MHL) Deserialize(reader io.Reader, out chan<- api.FileInfo, predicate func(*api.FileInfo) bool) error

func (*MHL) Extension added in v1.1.0

func (m *MHL) Extension() string

func (*MHL) Serialize added in v1.1.0

func (m *MHL) Serialize(in <-chan api.FileInfo, writer io.Writer) (err error)

type SignatureMismatchError added in v1.1.0

type SignatureMismatchError struct {
	DecodeError
}

func (*SignatureMismatchError) Error added in v1.1.0

func (s *SignatureMismatchError) Error() string

Jump to

Keyboard shortcuts

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