blob: 38db0d51ccef039554c80025d48dc87932404f5d [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001package zstd
2
3/*
4#define ZSTD_STATIC_LINKING_ONLY
5#include "zstd.h"
6*/
7import "C"
8
9// ErrorCode is an error returned by the zstd library.
10type ErrorCode int
11
12// Error returns the error string given by zstd
13func (e ErrorCode) Error() string {
14 return C.GoString(C.ZSTD_getErrorName(C.size_t(e)))
15}
16
17func cIsError(code int) bool {
18 return int(C.ZSTD_isError(C.size_t(code))) != 0
19}
20
21// getError returns an error for the return code, or nil if it's not an error
22func getError(code int) error {
23 if code < 0 && cIsError(code) {
24 return ErrorCode(code)
25 }
26 return nil
27}
28
29// IsDstSizeTooSmallError returns whether the error correspond to zstd standard sDstSizeTooSmall error
30func IsDstSizeTooSmallError(e error) bool {
31 if e != nil && e.Error() == "Destination buffer is too small" {
32 return true
33 }
34 return false
35}