rsync

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

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

Go to latest
Published: Dec 24, 2023 License: Zlib Imports: 4 Imported by: 0

README

rsync-go

MIT licensed Build Status GoDoc

This is a pure go implementation of the rsync algorithm.

This repo in particular is a fork of Daniel Teophanes's implementation (see the section for details)

Usage

A simple example is provided in examples.

Import

Creating a signature:

Documentation

Overview

RSync/RDiff implementation.

Algorithm found at: http://www.samba.org/~tridge/phd_thesis.pdf

Definitions

Source: The final content.
Target: The content to be made into final content.
Signature: The sequence of hashes used to identify the content.

Index

Constants

View Source
const DefaultBlockSize = 1024 * 6

If no BlockSize is specified in the RSync instance, this value is used.

View Source
const DefaultMaxDataOp = DefaultBlockSize * 10

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockHash

type BlockHash struct {
	Index      uint64
	StrongHash []byte
	WeakHash   uint32
}

Signature hash item generated from target.

type OpType

type OpType byte

Operation Types.

const (
	OpBlock OpType = iota
	OpData
	OpHash
	OpBlockRange
)

type Operation

type Operation struct {
	Type          OpType
	BlockIndex    uint64
	BlockIndexEnd uint64
	Data          []byte
}

Instruction to mutate target to align to source.

type OperationWriter

type OperationWriter func(op Operation) error

type RSync

type RSync struct {
	BlockSize int
	MaxDataOp int

	// If this is nil an MD5 hash is used.
	UniqueHasher hash.Hash
	// contains filtered or unexported fields
}

Properties to use while working with the rsync algorithm. A single RSync should not be used concurrently as it may contain internal buffers and hash sums.

func (*RSync) ApplyDelta

func (r *RSync) ApplyDelta(alignedTarget io.Writer, target io.ReadSeeker, ops chan Operation) error

Apply the difference to the target.

func (*RSync) BlockHashCount

func (r *RSync) BlockHashCount(targetLength int) (count int)

If the target length is known the number of hashes in the signature can be determined.

func (*RSync) CreateDelta

func (r *RSync) CreateDelta(source io.Reader, signature []BlockHash, ops OperationWriter) (err error)

Create the operation list to mutate the target signature into the source. Any data operation from the OperationWriter must have the data copied out within the span of the function; the data buffer underlying the operation data is reused. The sourceSum create a complete hash sum of the source if present.

func (*RSync) CreateSignature

func (r *RSync) CreateSignature(target io.Reader, sw SignatureWriter) error

Calculate the signature of target.

type SignatureWriter

type SignatureWriter func(bl BlockHash) error

Write signatures as they are generated.

Jump to

Keyboard shortcuts

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