librsync

package module
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: Apache-2.0 Imports: 9 Imported by: 9

README

librsync-go

librsync-go is a reimplementation of librsync in Go.

Installing

To install the rdiff utility:

go install github.com/balena-os/librsync-go/cmd/rdiff

To use it as a library simply include github.com/balena-os/librsync-go in your import statement

Contributing

If you're interested in contributing, that's awesome!

Pull requests

Here's a few guidelines to make the process easier for everyone involved.

  • We use Versionist to manage versioning (and in particular, semantic versioning) and generate the changelog for this project.
  • At least one commit in a PR should have a Change-Type: type footer, where type can be patch, minor or major. The subject of this commit will be added to the changelog.
  • Commits should be squashed as much as makes sense.
  • Commits should be signed-off (git commit -s)

Documentation

Index

Constants

View Source
const (
	MATCH_KIND_LITERAL matchKind = iota
	MATCH_KIND_COPY
)
View Source
const (
	BLAKE2_SUM_LENGTH = 32
	MD4_SUM_LENGTH    = 16
)
View Source
const OUTPUT_BUFFER_SIZE = 16 * 1024 * 1024

Size of the output buffer in bytes. We'll flush the match once it gets this large. As consequence, this is the maximum size of a LITERAL command we'll generate on our deltas.

View Source
const ROLLSUM_CHAR_OFFSET = 31

Variables

This section is empty.

Functions

func CalcStrongSum

func CalcStrongSum(data []byte, sigType MagicNumber, strongLen uint32) ([]byte, error)

func Delta

func Delta(sig *SignatureType, i io.Reader, output io.Writer) error

func DeltaBuff added in v0.8.0

func DeltaBuff(sig *SignatureType, i io.Reader, output io.Writer, litBuff []byte) error

DeltaBuff like Delta but allows to pass literal buffer slice. This is useful for efficient computation of multiple deltas.

The slice shall have zero size, and capacity of OUTPUT_BUFFER_SIZE.

Example of usage:

var files []string
var litBuff = make([]byte, 0, OUTPUT_BUFFER_SIZE)
for _, file := range files {
  f, _ := os.Open(file)
  sig, _ := ReadSignatureFile(file + ".sig")
  delta, _ := os.OpenFile(file+".delta", os.O_CREATE|os.O_WRONLY, 0644)
  _ = DeltaBuff(sig, f, delta, litBuff)
}

func Patch

func Patch(base io.ReadSeeker, delta io.Reader, out io.Writer) error

func WeakChecksum

func WeakChecksum(data []byte) uint32

Types

type Command

type Command struct {
	Kind      OpKind
	Immediate uint8
	Len1      uint8
	Len2      uint8
}

type MagicNumber

type MagicNumber uint32
const (
	DELTA_MAGIC MagicNumber = 0x72730236

	// A signature file with MD4 signatures.
	//
	// Backward compatible with librsync < 1.0, but strongly deprecated because
	// it creates a security vulnerability on files containing partly untrusted
	// data. See <https://github.com/librsync/librsync/issues/5>.
	MD4_SIG_MAGIC MagicNumber = 0x72730136

	// A signature file using the BLAKE2 hash. Supported from librsync 1.0.
	BLAKE2_SIG_MAGIC MagicNumber = 0x72730137
)

type Op

type Op uint8
const (
	OP_END Op = iota
	OP_LITERAL_1
	OP_LITERAL_2
	OP_LITERAL_3
	OP_LITERAL_4
	OP_LITERAL_5
	OP_LITERAL_6
	OP_LITERAL_7
	OP_LITERAL_8
	OP_LITERAL_9
	OP_LITERAL_10
	OP_LITERAL_11
	OP_LITERAL_12
	OP_LITERAL_13
	OP_LITERAL_14
	OP_LITERAL_15
	OP_LITERAL_16
	OP_LITERAL_17
	OP_LITERAL_18
	OP_LITERAL_19
	OP_LITERAL_20
	OP_LITERAL_21
	OP_LITERAL_22
	OP_LITERAL_23
	OP_LITERAL_24
	OP_LITERAL_25
	OP_LITERAL_26
	OP_LITERAL_27
	OP_LITERAL_28
	OP_LITERAL_29
	OP_LITERAL_30
	OP_LITERAL_31
	OP_LITERAL_32
	OP_LITERAL_33
	OP_LITERAL_34
	OP_LITERAL_35
	OP_LITERAL_36
	OP_LITERAL_37
	OP_LITERAL_38
	OP_LITERAL_39
	OP_LITERAL_40
	OP_LITERAL_41
	OP_LITERAL_42
	OP_LITERAL_43
	OP_LITERAL_44
	OP_LITERAL_45
	OP_LITERAL_46
	OP_LITERAL_47
	OP_LITERAL_48
	OP_LITERAL_49
	OP_LITERAL_50
	OP_LITERAL_51
	OP_LITERAL_52
	OP_LITERAL_53
	OP_LITERAL_54
	OP_LITERAL_55
	OP_LITERAL_56
	OP_LITERAL_57
	OP_LITERAL_58
	OP_LITERAL_59
	OP_LITERAL_60
	OP_LITERAL_61
	OP_LITERAL_62
	OP_LITERAL_63
	OP_LITERAL_64
	OP_LITERAL_N1
	OP_LITERAL_N2
	OP_LITERAL_N4
	OP_LITERAL_N8
	OP_COPY_N1_N1
	OP_COPY_N1_N2
	OP_COPY_N1_N4
	OP_COPY_N1_N8
	OP_COPY_N2_N1
	OP_COPY_N2_N2
	OP_COPY_N2_N4
	OP_COPY_N2_N8
	OP_COPY_N4_N1
	OP_COPY_N4_N2
	OP_COPY_N4_N4
	OP_COPY_N4_N8
	OP_COPY_N8_N1
	OP_COPY_N8_N2
	OP_COPY_N8_N4
	OP_COPY_N8_N8
	OP_RESERVED_85
	OP_RESERVED_86
	OP_RESERVED_87
	OP_RESERVED_88
	OP_RESERVED_89
	OP_RESERVED_90
	OP_RESERVED_91
	OP_RESERVED_92
	OP_RESERVED_93
	OP_RESERVED_94
	OP_RESERVED_95
	OP_RESERVED_96
	OP_RESERVED_97
	OP_RESERVED_98
	OP_RESERVED_99
	OP_RESERVED_100
	OP_RESERVED_101
	OP_RESERVED_102
	OP_RESERVED_103
	OP_RESERVED_104
	OP_RESERVED_105
	OP_RESERVED_106
	OP_RESERVED_107
	OP_RESERVED_108
	OP_RESERVED_109
	OP_RESERVED_110
	OP_RESERVED_111
	OP_RESERVED_112
	OP_RESERVED_113
	OP_RESERVED_114
	OP_RESERVED_115
	OP_RESERVED_116
	OP_RESERVED_117
	OP_RESERVED_118
	OP_RESERVED_119
	OP_RESERVED_120
	OP_RESERVED_121
	OP_RESERVED_122
	OP_RESERVED_123
	OP_RESERVED_124
	OP_RESERVED_125
	OP_RESERVED_126
	OP_RESERVED_127
	OP_RESERVED_128
	OP_RESERVED_129
	OP_RESERVED_130
	OP_RESERVED_131
	OP_RESERVED_132
	OP_RESERVED_133
	OP_RESERVED_134
	OP_RESERVED_135
	OP_RESERVED_136
	OP_RESERVED_137
	OP_RESERVED_138
	OP_RESERVED_139
	OP_RESERVED_140
	OP_RESERVED_141
	OP_RESERVED_142
	OP_RESERVED_143
	OP_RESERVED_144
	OP_RESERVED_145
	OP_RESERVED_146
	OP_RESERVED_147
	OP_RESERVED_148
	OP_RESERVED_149
	OP_RESERVED_150
	OP_RESERVED_151
	OP_RESERVED_152
	OP_RESERVED_153
	OP_RESERVED_154
	OP_RESERVED_155
	OP_RESERVED_156
	OP_RESERVED_157
	OP_RESERVED_158
	OP_RESERVED_159
	OP_RESERVED_160
	OP_RESERVED_161
	OP_RESERVED_162
	OP_RESERVED_163
	OP_RESERVED_164
	OP_RESERVED_165
	OP_RESERVED_166
	OP_RESERVED_167
	OP_RESERVED_168
	OP_RESERVED_169
	OP_RESERVED_170
	OP_RESERVED_171
	OP_RESERVED_172
	OP_RESERVED_173
	OP_RESERVED_174
	OP_RESERVED_175
	OP_RESERVED_176
	OP_RESERVED_177
	OP_RESERVED_178
	OP_RESERVED_179
	OP_RESERVED_180
	OP_RESERVED_181
	OP_RESERVED_182
	OP_RESERVED_183
	OP_RESERVED_184
	OP_RESERVED_185
	OP_RESERVED_186
	OP_RESERVED_187
	OP_RESERVED_188
	OP_RESERVED_189
	OP_RESERVED_190
	OP_RESERVED_191
	OP_RESERVED_192
	OP_RESERVED_193
	OP_RESERVED_194
	OP_RESERVED_195
	OP_RESERVED_196
	OP_RESERVED_197
	OP_RESERVED_198
	OP_RESERVED_199
	OP_RESERVED_200
	OP_RESERVED_201
	OP_RESERVED_202
	OP_RESERVED_203
	OP_RESERVED_204
	OP_RESERVED_205
	OP_RESERVED_206
	OP_RESERVED_207
	OP_RESERVED_208
	OP_RESERVED_209
	OP_RESERVED_210
	OP_RESERVED_211
	OP_RESERVED_212
	OP_RESERVED_213
	OP_RESERVED_214
	OP_RESERVED_215
	OP_RESERVED_216
	OP_RESERVED_217
	OP_RESERVED_218
	OP_RESERVED_219
	OP_RESERVED_220
	OP_RESERVED_221
	OP_RESERVED_222
	OP_RESERVED_223
	OP_RESERVED_224
	OP_RESERVED_225
	OP_RESERVED_226
	OP_RESERVED_227
	OP_RESERVED_228
	OP_RESERVED_229
	OP_RESERVED_230
	OP_RESERVED_231
	OP_RESERVED_232
	OP_RESERVED_233
	OP_RESERVED_234
	OP_RESERVED_235
	OP_RESERVED_236
	OP_RESERVED_237
	OP_RESERVED_238
	OP_RESERVED_239
	OP_RESERVED_240
	OP_RESERVED_241
	OP_RESERVED_242
	OP_RESERVED_243
	OP_RESERVED_244
	OP_RESERVED_245
	OP_RESERVED_246
	OP_RESERVED_247
	OP_RESERVED_248
	OP_RESERVED_249
	OP_RESERVED_250
	OP_RESERVED_251
	OP_RESERVED_252
	OP_RESERVED_253
	OP_RESERVED_254
	OP_RESERVED_255
)

type OpKind

type OpKind uint16
const (
	KIND_END OpKind = iota + 1000
	KIND_LITERAL
	KIND_SIGNATURE
	KIND_COPY
	KIND_CHECKSUM
	KIND_RESERVED
)

type Rollsum

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

func NewRollsum

func NewRollsum() Rollsum

func (*Rollsum) Digest

func (r *Rollsum) Digest() uint32

func (*Rollsum) Reset

func (r *Rollsum) Reset()

func (*Rollsum) Rollin

func (r *Rollsum) Rollin(in byte)

func (*Rollsum) Rollout

func (r *Rollsum) Rollout(out byte)

func (*Rollsum) Rotate

func (r *Rollsum) Rotate(out, in byte)

func (*Rollsum) Update

func (r *Rollsum) Update(p []byte)

type SignatureType

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

func ReadSignature added in v0.3.0

func ReadSignature(r io.Reader) (*SignatureType, error)

ReadSignature reads a signature from an io.Reader.

func ReadSignatureFile added in v0.3.0

func ReadSignatureFile(path string) (*SignatureType, error)

ReadSignatureFile reads a signature from the file at path.

func Signature

func Signature(input io.Reader, output io.Writer, blockLen, strongLen uint32, sigType MagicNumber) (*SignatureType, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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