-
Notifications
You must be signed in to change notification settings - Fork 0
/
zstd.go
58 lines (45 loc) · 1.1 KB
/
zstd.go
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
54
55
56
57
58
package zstd_marshal
import (
"github.com/klauspost/compress/zstd"
"runtime"
)
// newZstdEncoder - for create encoder instance
func newZstdEncoder() *zstdEncoder {
encoder, err := zstd.NewWriter(nil)
if err != nil {
panic(err)
}
return &zstdEncoder{
encoder,
}
}
// newZstdEncoderWithConcurrency - for create encoder instance with concurrency
func newZstdEncoderWithConcurrency(encoderConcurrency int) *zstdEncoder {
encoder, err := zstd.NewWriter(nil, zstd.WithEncoderConcurrency(encoderConcurrency))
if err != nil {
panic(err)
}
return &zstdEncoder{
encoder,
}
}
// newZstdDecoderWithConcurrency - for create decoder instance with concurrency
func newZstdDecoderWithConcurrency(encoderConcurrency int) *zstdDecoder {
decoder, err := zstd.NewReader(nil, zstd.WithDecoderConcurrency(runtime.GOMAXPROCS(encoderConcurrency)))
if err != nil {
panic(err)
}
return &zstdDecoder{
decoder,
}
}
// newZstdDecoder - for create decoder instance
func newZstdDecoder() *zstdDecoder {
decoder, err := zstd.NewReader(nil)
if err != nil {
panic(err)
}
return &zstdDecoder{
decoder,
}
}