Skip to content

Commit 3f2cf79

Browse files
committed
Add zstd compression
1 parent 36154a6 commit 3f2cf79

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

compress.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"fmt"
1313
"io"
1414

15+
zstd "github.com/klauspost/compress/zstd"
1516
"github.com/pierrec/lz4/v4"
1617
lzo "github.com/rasky/go-lzo"
1718
)
@@ -51,6 +52,14 @@ func (nfFile *NfFile) uncompressBlock(blockHeader *DataBlockHeader) ([]byte, err
5152
out = out[:n]
5253
dataBlock = out
5354
blockHeader.Size = uint32(n)
55+
case ZSTD_COMPRESSED:
56+
var decoder, _ = zstd.NewReader(nil, zstd.WithDecoderConcurrency(0))
57+
out, err := decoder.DecodeAll(dataBlock, nil)
58+
if err != nil {
59+
return nil, fmt.Errorf("nfFile uncompress zstd data block: %v", err)
60+
}
61+
dataBlock = out
62+
blockHeader.Size = uint32(len(out))
5463
default:
5564
return nil, fmt.Errorf("unknown data block compression: %d", nfFile.Header.Compression)
5665
}

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module github.com/phaag/go-nfdump
22

3-
go 1.17
3+
go 1.21
44

55
require (
6+
github.com/klauspost/compress v1.17.8
67
github.com/pierrec/lz4/v4 v4.1.17
78
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e
89
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
2+
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
13
github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc=
24
github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
35
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e h1:dCWirM5F3wMY+cmRda/B1BiPsFtmzXqV9b0hLWtVBMs=

nffile.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const NOT_COMPRESSED = 0
2727
const LZO_COMPRESSED = 1
2828
const BZ2_COMPRESSED = 2
2929
const LZ4_COMPRESSED = 3
30+
const ZSTD_COMPRESSED = 4
3031

3132
const BUFFSIZE = 5 * 1048576
3233

@@ -40,6 +41,7 @@ type NfFileHeader struct {
4041
// LZO_COMPRESSED 1
4142
// BZ2_COMPRESSED 2
4243
// LZ4_COMPRESSED 3
44+
// ZSTD_COMPRESSED 4
4345
Encryption uint8 // type of encryption
4446
// NOT_ENCRYPTED 0
4547
AppendixBlocks uint16 // number of blocks to read from appendix

0 commit comments

Comments
 (0)