MCPcopy
hub / github.com/klauspost/compress / testSnappyDecode

Function testSnappyDecode

s2/s2_test.go:1367–1395  ·  view source on GitHub ↗
(t *testing.T, src []byte)

Source from the content-addressed store, hash-verified

1365}
1366
1367func testSnappyDecode(t *testing.T, src []byte) {
1368 var buf bytes.Buffer
1369 enc := snapref.NewBufferedWriter(&buf)
1370 n, err := enc.Write(src)
1371 if err != nil {
1372 t.Error(err)
1373 return
1374 }
1375 if n != len(src) {
1376 t.Error(io.ErrShortWrite)
1377 return
1378 }
1379 enc.Close()
1380 t.Logf("encoded to %d -> %d bytes", len(src), buf.Len())
1381 dec := NewReader(&buf)
1382 decoded, err := io.ReadAll(dec)
1383 if err != nil {
1384 t.Error(err)
1385 return
1386 }
1387 if len(decoded) != len(src) {
1388 t.Error("decoded len:", len(decoded), "!=", len(src))
1389 return
1390 }
1391 err = cmp(src, decoded)
1392 if err != nil {
1393 t.Error(err)
1394 }
1395}
1396
1397func benchDecode(b *testing.B, src []byte) {
1398 b.Run("default", func(b *testing.B) {

Callers 2

testFileFunction · 0.85
TestDataRoundtripsFunction · 0.85

Calls 7

NewBufferedWriterFunction · 0.92
LenMethod · 0.80
NewReaderFunction · 0.70
cmpFunction · 0.70
WriteMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…