forked from balacode/go-delta
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelta.go
More file actions
53 lines (44 loc) · 2.34 KB
/
delta.go
File metadata and controls
53 lines (44 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// -----------------------------------------------------------------------------
// github.com/balacode/go-delta go-delta/[delta.go]
// (c) balarabe@protonmail.com License: MIT
// -----------------------------------------------------------------------------
package delta
// Delta stores the binary delta difference between two byte arrays
type Delta struct {
sourceSize int // size of the source array
sourceHash []byte // hash of the source byte array
targetSize int // size of the target array
targetHash []byte // hash of the result after this Delta is applied
newCount int // number of chunks not matched in source array
oldCount int // number of matched chunks in source array
parts []deltaPart // array referring to chunks in source array,
// or new bytes to append
} // Delta
// deltaPart stores references to chunks in the source array,
// or specifies bytes to append to result array directly
type deltaPart struct {
sourceLoc int // byte position of the chunk in source array,
// or -1 when 'data' supplies the bytes directly
//
size int // size of the chunk in bytes
data []byte // optional bytes (only when sourceLoc is -1)
} // deltaPart
// -----------------------------------------------------------------------------
// # Read-Only Properties
// NewCount returns the number of chunks not matched in source array.
func (ob *Delta) NewCount() int {
return ob.newCount
} // NewCount
// OldCount returns the number of matched chunks in source array.
func (ob *Delta) OldCount() int {
return ob.oldCount
} // OldCount
// SourceSize returns the size of the source byte array, in bytes.
func (ob *Delta) SourceSize() int {
return ob.sourceSize
} // SourceSize
// TargetSize returns the size of the target byte array, in bytes.
func (ob *Delta) TargetSize() int {
return ob.targetSize
} // TargetSize
// end