MCPcopy Create free account
hub / github.com/brimdata/super / compressBuffer

Function compressBuffer

csup/segment.go:66–90  ·  view source on GitHub ↗

XXX for now we always compress, we should add a config option to avoid compression when local storage is fast compared to compute

(b []byte)

Source from the content-addressed store, hash-verified

64// XXX for now we always compress, we should add a config option to
65// avoid compression when local storage is fast compared to compute
66func compressBuffer(b []byte) (uint8, []byte, error) {
67 inLen := len(b)
68 if inLen == 0 {
69 return CompressionFormatNone, nil, nil
70 }
71 zbuf := zbufPool.Get().(*[]byte)
72 defer zbufPool.Put(zbuf)
73 // Use inLen-1 so compression will fail if it doesn't result in
74 // fewer bytes. XXX make the -1 a bigger gap
75 *zbuf = slices.Grow((*zbuf)[:0], inLen-1)[:inLen-1]
76 var c lz4.Compressor
77 zlen, err := c.CompressBlock(b, *zbuf)
78 if err != nil && err != lz4.ErrInvalidSourceShortBuffer {
79 return 0, nil, err
80 }
81 if zlen > 0 {
82 // Compression succeeded. Copy bytes... XXX we should
83 // have a way to stash the buffer in the Primitive and
84 // release it after written.
85 bytes := make([]byte, zlen)
86 copy(bytes, *zbuf)
87 return CompressionFormatLZ4, bytes, nil
88 }
89 return CompressionFormatNone, b, nil
90}

Callers 3

EncodeMethod · 0.85
EncodeMethod · 0.85
EncodeMethod · 0.85

Calls 3

GrowMethod · 0.80
GetMethod · 0.65
PutMethod · 0.65

Tested by

no test coverage detected