LCOV - code coverage report
Current view: top level - pebble/sstable - compression_cgo.go (source / functions) Hit Total Coverage
Test: 2023-12-01 08:08Z 51fca96d - tests + meta.lcov Lines: 10 10 100.0 %
Date: 2023-12-01 08:09:44 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2021 The LevelDB-Go and Pebble Authors. All rights reserved. Use
       2             : // of this source code is governed by a BSD-style license that can be found in
       3             : // the LICENSE file.
       4             : 
       5             : //go:build cgo
       6             : // +build cgo
       7             : 
       8             : package sstable
       9             : 
      10             : import (
      11             :         "bytes"
      12             : 
      13             :         "github.com/DataDog/zstd"
      14             : )
      15             : 
      16             : // decodeZstd decompresses b with the Zstandard algorithm.
      17             : // It reuses the preallocated capacity of decodedBuf if it is sufficient.
      18             : // On success, it returns the decoded byte slice.
      19           2 : func decodeZstd(decodedBuf, b []byte) ([]byte, error) {
      20           2 :         return zstd.Decompress(decodedBuf, b)
      21           2 : }
      22             : 
      23             : // encodeZstd compresses b with the Zstandard algorithm at default compression
      24             : // level (level 3). It reuses the preallocated capacity of compressedBuf if it
      25             : // is sufficient. The subslice `compressedBuf[:varIntLen]` should already encode
      26             : // the length of `b` before calling encodeZstd. It returns the encoded byte
      27             : // slice, including the `compressedBuf[:varIntLen]` prefix.
      28           2 : func encodeZstd(compressedBuf []byte, varIntLen int, b []byte) []byte {
      29           2 :         buf := bytes.NewBuffer(compressedBuf[:varIntLen])
      30           2 :         writer := zstd.NewWriterLevel(buf, 3)
      31           2 :         writer.Write(b)
      32           2 :         writer.Close()
      33           2 :         return buf.Bytes()
      34           2 : }

Generated by: LCOV version 1.14