...
1
2
3
4 package zstd
5
6 import (
7 "bytes"
8 "encoding/binary"
9 "errors"
10 "log"
11 "math"
12 )
13
14
15 const debug = false
16
17
18 const debugEncoder = debug
19
20
21 const debugDecoder = debug
22
23
24 const debugAsserts = debug || false
25
26
27 const debugSequences = false
28
29
30 const debugMatches = false
31
32
33 const forcePreDef = false
34
35
36 const zstdMinMatch = 3
37
38
39 const fcsUnknown = math.MaxUint64
40
41 var (
42
43
44 ErrReservedBlockType = errors.New("invalid input: reserved block type encountered")
45
46
47
48 ErrCompressedSizeTooBig = errors.New("invalid input: compressed size too big")
49
50
51
52 ErrBlockTooSmall = errors.New("block too small")
53
54
55
56 ErrUnexpectedBlockSize = errors.New("unexpected block size")
57
58
59
60 ErrMagicMismatch = errors.New("invalid input: magic number mismatch")
61
62
63
64 ErrWindowSizeExceeded = errors.New("window size exceeded")
65
66
67
68 ErrWindowSizeTooSmall = errors.New("invalid input: window size was too small")
69
70
71 ErrDecoderSizeExceeded = errors.New("decompressed size exceeds configured limit")
72
73
74 ErrUnknownDictionary = errors.New("unknown dictionary")
75
76
77
78 ErrFrameSizeExceeded = errors.New("frame size exceeded")
79
80
81
82 ErrFrameSizeMismatch = errors.New("frame size does not match size on stream")
83
84
85 ErrCRCMismatch = errors.New("CRC check failed")
86
87
88
89 ErrDecoderClosed = errors.New("decoder used after Close")
90
91
92
93 ErrDecoderNilInput = errors.New("nil input provided as reader")
94 )
95
96 func println(a ...interface{}) {
97 if debug || debugDecoder || debugEncoder {
98 log.Println(a...)
99 }
100 }
101
102 func printf(format string, a ...interface{}) {
103 if debug || debugDecoder || debugEncoder {
104 log.Printf(format, a...)
105 }
106 }
107
108 func load3232(b []byte, i int32) uint32 {
109 return binary.LittleEndian.Uint32(b[:len(b):len(b)][i:])
110 }
111
112 func load6432(b []byte, i int32) uint64 {
113 return binary.LittleEndian.Uint64(b[:len(b):len(b)][i:])
114 }
115
116 type byter interface {
117 Bytes() []byte
118 Len() int
119 }
120
121 var _ byter = &bytes.Buffer{}
122
View as plain text