You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: xerial.go
    path of file: ./repos/compress/snappy/xerial
    
    the code of the file until where you have to start completion: package xerial

import (
	"bytes"
	"encoding/binary"
	"errors"

	"github.com/klauspost/compress/s2"
)

var (
	xerialHeader = []byte{130, 83, 78, 65, 80, 80, 89, 0}

	// This is xerial version 1 and minimally compatible with version 1
	xerialVersionInfo = []byte{0, 0, 0, 1, 0, 0, 0, 1}

	// ErrMalformed is returned by the decoder when the xerial framing
	// is malformed
	ErrMalformed = errors.New("malformed xerial framing")
)

// Encode *appends* to the specified 'dst' the compressed
// 'src' in xerial framing format. If 'dst' does not have enough
// capacity, then a new slice will be allocated. If 'dst' has
// non-zero length, then if *must* have been built using this function.
func Encode(dst, src []byte) []byte {
	if len(dst) == 0 {
		dst = append(dst, xerialHeader...)
		dst = append(dst, xerialVersionInfo...)
	}

	// Snappy encode in blocks of maximum 32KB
	var (
		max       = len(src)
		blockSize = 32 * 1024
		pos       = 0
		chunk     []byte
	)

	for pos < max {
		newPos := min(pos+blockSize, max)
		// Find maximum length we need
		needLen := s2.MaxE
    
func DecodeCapped(dst, src []byte) ([]byte, error) {
	var max = len(src)
	if dst == nil {
		return nil, ErrDstTooSmall
	}
	if max < len(xerialHeader) || !bytes.Equal(src[:8], xerialHeader) {
		l, err := s2.DecodedLen(src)
		if err != nil {
			return nil, ErrMalformed
		}
		if l > cap(dst) {
			return nil, ErrDstTooSmall
		}
		return s2.Decode(dst[:cap(dst)], src)
	}
	dst = dst[:0]
	if max == sizeOffset {
		return dst, nil
	}
	if max < sizeOffset+sizeBytes {
		return nil, ErrMalformed
	}
	pos := sizeOffset

	for pos+sizeBytes <= max {
		size := int(binary.BigEndian.Uint32(src[pos : pos+sizeBytes]))
		pos += sizeBytes

		nextPos := pos + size
		// On architectures where int is 32-bytes wide size + pos could
		// overflow so we need to check the low bound as well as the
		// high
		if nextPos < pos || nextPos > max {
			return nil, ErrMalformed
		}
		nextLen, err := s2.DecodedLen(src[pos:nextPos])
		if err != nil {
			return nil, err
		}
		if cap(dst)-len(dst) < nextLen {
			return nil, ErrDstTooSmall
		}
		// Decode directly into dst
		dstStart := len(dst)
		dstEnd := dstStart + nextLen
		_, err = s2.Decode(dst[dstStart:dstEnd], src[pos:nextPos])
		if err != nil {
			return nil, err
		}
		dst = dst[:dstEnd]
		pos = nextPos
	}
	return dst, nil
}