...

Source file src/github.com/klauspost/compress/zstd/zstd.go

Documentation: github.com/klauspost/compress/zstd

     1  // Package zstd provides decompression of zstandard files.
     2  //
     3  // For advanced usage and examples, go to the README: https://github.com/klauspost/compress/tree/master/zstd#zstd
     4  package zstd
     5  
     6  import (
     7  	"bytes"
     8  	"encoding/binary"
     9  	"errors"
    10  	"log"
    11  	"math"
    12  )
    13  
    14  // enable debug printing
    15  const debug = false
    16  
    17  // enable encoding debug printing
    18  const debugEncoder = debug
    19  
    20  // enable decoding debug printing
    21  const debugDecoder = debug
    22  
    23  // Enable extra assertions.
    24  const debugAsserts = debug || false
    25  
    26  // print sequence details
    27  const debugSequences = false
    28  
    29  // print detailed matching information
    30  const debugMatches = false
    31  
    32  // force encoder to use predefined tables.
    33  const forcePreDef = false
    34  
    35  // zstdMinMatch is the minimum zstd match length.
    36  const zstdMinMatch = 3
    37  
    38  // fcsUnknown is used for unknown frame content size.
    39  const fcsUnknown = math.MaxUint64
    40  
    41  var (
    42  	// ErrReservedBlockType is returned when a reserved block type is found.
    43  	// Typically this indicates wrong or corrupted input.
    44  	ErrReservedBlockType = errors.New("invalid input: reserved block type encountered")
    45  
    46  	// ErrCompressedSizeTooBig is returned when a block is bigger than allowed.
    47  	// Typically this indicates wrong or corrupted input.
    48  	ErrCompressedSizeTooBig = errors.New("invalid input: compressed size too big")
    49  
    50  	// ErrBlockTooSmall is returned when a block is too small to be decoded.
    51  	// Typically returned on invalid input.
    52  	ErrBlockTooSmall = errors.New("block too small")
    53  
    54  	// ErrUnexpectedBlockSize is returned when a block has unexpected size.
    55  	// Typically returned on invalid input.
    56  	ErrUnexpectedBlockSize = errors.New("unexpected block size")
    57  
    58  	// ErrMagicMismatch is returned when a "magic" number isn't what is expected.
    59  	// Typically this indicates wrong or corrupted input.
    60  	ErrMagicMismatch = errors.New("invalid input: magic number mismatch")
    61  
    62  	// ErrWindowSizeExceeded is returned when a reference exceeds the valid window size.
    63  	// Typically this indicates wrong or corrupted input.
    64  	ErrWindowSizeExceeded = errors.New("window size exceeded")
    65  
    66  	// ErrWindowSizeTooSmall is returned when no window size is specified.
    67  	// Typically this indicates wrong or corrupted input.
    68  	ErrWindowSizeTooSmall = errors.New("invalid input: window size was too small")
    69  
    70  	// ErrDecoderSizeExceeded is returned if decompressed size exceeds the configured limit.
    71  	ErrDecoderSizeExceeded = errors.New("decompressed size exceeds configured limit")
    72  
    73  	// ErrUnknownDictionary is returned if the dictionary ID is unknown.
    74  	ErrUnknownDictionary = errors.New("unknown dictionary")
    75  
    76  	// ErrFrameSizeExceeded is returned if the stated frame size is exceeded.
    77  	// This is only returned if SingleSegment is specified on the frame.
    78  	ErrFrameSizeExceeded = errors.New("frame size exceeded")
    79  
    80  	// ErrFrameSizeMismatch is returned if the stated frame size does not match the expected size.
    81  	// This is only returned if SingleSegment is specified on the frame.
    82  	ErrFrameSizeMismatch = errors.New("frame size does not match size on stream")
    83  
    84  	// ErrCRCMismatch is returned if CRC mismatches.
    85  	ErrCRCMismatch = errors.New("CRC check failed")
    86  
    87  	// ErrDecoderClosed will be returned if the Decoder was used after
    88  	// Close has been called.
    89  	ErrDecoderClosed = errors.New("decoder used after Close")
    90  
    91  	// ErrDecoderNilInput is returned when a nil Reader was provided
    92  	// and an operation other than Reset/DecodeAll/Close was attempted.
    93  	ErrDecoderNilInput = errors.New("nil input provided as reader")
    94  )
    95  
    96  func println(a ...interface{}) {
    97  	if debug || debugDecoder || debugEncoder {
    98  		log.Println(a...)
    99  	}
   100  }
   101  
   102  func printf(format string, a ...interface{}) {
   103  	if debug || debugDecoder || debugEncoder {
   104  		log.Printf(format, a...)
   105  	}
   106  }
   107  
   108  func load3232(b []byte, i int32) uint32 {
   109  	return binary.LittleEndian.Uint32(b[:len(b):len(b)][i:])
   110  }
   111  
   112  func load6432(b []byte, i int32) uint64 {
   113  	return binary.LittleEndian.Uint64(b[:len(b):len(b)][i:])
   114  }
   115  
   116  type byter interface {
   117  	Bytes() []byte
   118  	Len() int
   119  }
   120  
   121  var _ byter = &bytes.Buffer{}
   122  

View as plain text