blob: a89c64012af47d217bb784197f04a69699f60de1 (
plain) (
blame)
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
|
// Package compress implements compression support.
package compress
import (
"fmt"
"github.com/go-faster/city"
)
//go:generate go run github.com/dmarkham/enumer -transform snake_upper -type Method -output method_enum.go
// Method is compression codec.
type Method byte
// Possible compression methods.
const (
None Method = 0x02
LZ4 Method = 0x82
ZSTD Method = 0x90
)
// Constants for compression encoding.
//
// See https://go-faster.org/docs/clickhouse/compression for reference.
const (
checksumSize = 16
compressHeaderSize = 1 + 4 + 4
headerSize = checksumSize + compressHeaderSize
// Limiting total data/block size to protect from possible OOM.
maxDataSize = 1024 * 1024 * 128 // 128MB
maxBlockSize = maxDataSize
hRawSize = 17
hDataSize = 21
hMethod = 16
)
// CorruptedDataErr means that provided hash mismatch with calculated.
type CorruptedDataErr struct {
Actual city.U128
Reference city.U128
RawSize int
DataSize int
}
func (c *CorruptedDataErr) Error() string {
return fmt.Sprintf("corrupted data: %s (actual), %s (reference), compressed size: %d, data size: %d",
FormatU128(c.Actual), FormatU128(c.Reference), c.RawSize, c.DataSize,
)
}
|