Scott Baker | eee8dd8 | 2019-09-24 12:52:34 -0700 | [diff] [blame] | 1 | package zstd |
| 2 | |
| 3 | /* |
| 4 | #define ZSTD_STATIC_LINKING_ONLY |
| 5 | #include "zstd.h" |
| 6 | */ |
| 7 | import "C" |
| 8 | |
| 9 | // ErrorCode is an error returned by the zstd library. |
| 10 | type ErrorCode int |
| 11 | |
| 12 | // Error returns the error string given by zstd |
| 13 | func (e ErrorCode) Error() string { |
| 14 | return C.GoString(C.ZSTD_getErrorName(C.size_t(e))) |
| 15 | } |
| 16 | |
| 17 | func 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 |
| 22 | func 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 |
| 30 | func IsDstSizeTooSmallError(e error) bool { |
| 31 | if e != nil && e.Error() == "Destination buffer is too small" { |
| 32 | return true |
| 33 | } |
| 34 | return false |
| 35 | } |