#include <stdint.h> #include <stdio.h> #include <zstd.h> #include "zstdseek.h" #include "vendor/zstdseek/zstd_seekable.h" /** * Returns zero if decompression fails, non-zero otherwise. */ size_t zstdseek_decompress( uint8_t *dest, size_t expected_len, uint8_t *compressed, size_t compressed_len ) { ZSTD_seekable *zs; size_t result; result = 0; zs = ZSTD_seekable_create(); if (zs == NULL) { fprintf(stderr, "ZSTD_seekable_create() failed"); goto out; } result = ZSTD_seekable_initBuff(zs, compressed, compressed_len); if (ZSTD_isError(result)) { fprintf(stderr, "ZSTD_seekable_init() error: %s\n", ZSTD_getErrorName(result)); result = 0; goto outfreezs; } result = ZSTD_seekable_decompress(zs, dest, expected_len, 0); if (ZSTD_isError(result)) { fprintf(stderr, "ZSTD_seekable_decompress() error: %s\n", ZSTD_getErrorName(result)); result = 0; goto outfreezs; } if (result != expected_len) { fprintf(stderr, "decoded %lu bytes, wanted %lu\n", result, expected_len); result = 0; } outfreezs: ZSTD_seekable_free(zs); out: return result; }