rsync

package module
v0.0.0-...-0a038bb Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2015 License: GPL-3.0 Imports: 12 Imported by: 1

README

rsync

This is rsync libary in pure golang.

Signature

func GenSign(rd io.Reader, rdLen int64, blockLen uint32, result io.Writer) (err error)

generate signature for rd.

Delta

func GenDelta(dstSig io.Reader, src io.ReadSeeker, srcLen int64, result io.Writer) (err error)

generate delta, and delta will write to result.

Patch

func Patch(deltaRd io.Reader, target io.ReadSeeker, merged io.Writer, args ...bool) (err error)

patch.

rdiff

Documentation

Index

Constants

View Source
const (
	DeltaMagic uint32 = 0x72730236
	BlakeMagic uint32 = 0x72730137
	Md4Magic   uint32 = 0x72730136

	TABLE_SIZE = (1 << 16)
	NULL_TAG   = -1
)
View Source
const (
	// RS_OP_LITERAL_Nx与librsync中的定义不同
	// RS_OP_LITERAL_Nx = librsync RS_OP_LITERAL_Nx - 0x40
	// 这样,使用高位字节来存储数据压缩方式
	RS_OP_LITERAL_N1 uint8 = 0x01
	RS_OP_LITERAL_N2 uint8 = 0x02
	RS_OP_LITERAL_N4 uint8 = 0x03
	RS_OP_LITERAL_N8 uint8 = 0x04

	// 压缩方式
	RS_COMPRESS_NONE  uint8 = 0x00
	RS_COMPRESS_BZIP2 uint8 = 0x10
	RS_COMPRESS_GZIP  uint8 = 0x20
	RS_COMPRESS_LZW   uint8 = 0x30
	RS_COMPRESS_FLATE uint8 = 0x40

	RS_OP_COPY_N1_N1 uint8 = 0x45
	RS_OP_COPY_N1_N2 uint8 = 0x46
	RS_OP_COPY_N1_N4 uint8 = 0x47
	RS_OP_COPY_N1_N8 uint8 = 0x48
	RS_OP_COPY_N2_N1 uint8 = 0x49
	RS_OP_COPY_N2_N2 uint8 = 0x4a
	RS_OP_COPY_N2_N4 uint8 = 0x4b
	RS_OP_COPY_N2_N8 uint8 = 0x4c
	RS_OP_COPY_N4_N1 uint8 = 0x4d
	RS_OP_COPY_N4_N2 uint8 = 0x4e
	RS_OP_COPY_N4_N4 uint8 = 0x4f
	RS_OP_COPY_N4_N8 uint8 = 0x50
	RS_OP_COPY_N8_N1 uint8 = 0x51
	RS_OP_COPY_N8_N2 uint8 = 0x52
	RS_OP_COPY_N8_N4 uint8 = 0x53
	RS_OP_COPY_N8_N8 uint8 = 0x54
)

Variables

View Source
var (
	NotDeltaMagic = errors.New("Not delta file format: magic wrong")
)

Functions

func Assert

func Assert(c bool, msg string)

func Assertf

func Assertf(c bool, format string, args ...interface{})

func Fuzz

func Fuzz(odata []byte) int

将输入的data随机分成两部分,一部分作为源,一部分作为目标,最终经过几个步骤后,目标与源相同 1 随机分为两部分, src, dst 2 对dst做signature, dst.sig 3 根据dst.sig和src做delta, dst-src.delta 4 使用dst-src.delta patch dst,得到新的target 5 比较target与src

func GenDelta

func GenDelta(dstSig io.Reader,
	src io.ReadSeeker,
	srcLen int64,
	result io.Writer,
	args ...bool) (err error)

generate delta param:

dstSig: reader of dst signature file
src: reader of src file
srcLen: src file content length
result: detla file writer

func GenSign

func GenSign(rd io.Reader, rdLen int64, blockLen uint32, result io.Writer) (err error)

generates signature

func Htonl

func Htonl(l uint32) []byte

func Htonll

func Htonll(ll uint64) []byte

func Htons

func Htons(s uint16) []byte

func NewRotateBuffer

func NewRotateBuffer(total int64, blockLen uint32, rd io.Reader) *rotateBuffer

total: rotateBuffer's buffer size blockLen: rotateBuffer block size rd: reader, which should feed the rotate buffer

func Patch

func Patch(deltaRd io.Reader, target io.ReadSeeker, merged io.Writer, args ...bool) (err error)

将差异merged文件 deltaRd: delta文件 target: 本地文件 merged: 合并后的文件

func PatchSelf

func PatchSelf(deltaRd io.Reader, target io.ReadWriteSeeker, args ...bool) (err error)

将差异直接写入target文件中,不单独创建merged文件 deltaRd: delta文件 target: 本地文件

Types

type Patcher

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

type SignHdr

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

type Signature

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

* This structure describes all the sums generated for an instance of * a file. It incorporates some redundancy to make it easier to * search.

func LoadSign

func LoadSign(rd io.Reader, debug bool) (sig *Signature, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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