L3HKOF4WYZZLJJY2Q6YJ65WGAB74GQ2A7ICD23M5NQGBP4BXF6DQC
CYS4NENLQIYU26KG46ZOTGWDOK5HX4UT4UW4ZKHY3PRPDWNGGT5QC
XTKRT6OQYN4LARQRDLI2KBSAJTOFZNT4AMBZ46CPUDZXD7IDYYWQC
XJ2PEH74CLJUELZBR47QHGUSKXB4Z5T7EKEF6Y4CYY2VBHZXUTDAC
PEUS54XQ5KJQYAVUYBG5MWLEHIOVPMZ3ANVC7HPQP6JUWWPRDW5AC
RIWSVVASWLJQQTSVRHIIUPENOZWOMHQLZMTQVGJUS2ZUGDPSWWIQC
Q7TKZCJP2Z75EICZYKCEZDHKGERSOKZGMTSU3UXETBHTF663T66AC
Y26WT3ZFN7KSVXOZ26B5Y2OR4M4VQYQLPMAHPC4O5VIT3ENBISXAC
2C2EF2GKTOAT7QI56KKDFGRGSFZRDPKUASNQFB6XQDROAEPPZW4AC
OBKF6SIIFFHHY7YWKPPX75N23NAVUD5662DKIHXSSIDPKKXQ5ZDQC
#ifndef ANI_ZSTDSEEK_H
#define ANI_ZSTDSEEK_H
/* Wrapper layer for working with the seekable variant of zstd. */
size_t zstdseek_decompress(uint8_t *, size_t, uint8_t *, size_t);
#endif
#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);
printf("decompress result: %lu\n", result);
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;
}
result = ZSTD_seekable_initBuff(zs, compressed, compressed_len);
if (ZSTD_isError(result)) {
fprintf(stderr, "ZSTD_seekable_init() error: %s\n",
ZSTD_getErrorName(result));
goto outfreezs;
}
result = ZSTD_seekable_decompress(zs, buf, expected_len, 0);
printf("decompress result: %lu\n", result);
if (ZSTD_isError(result)) {
fprintf(stderr, "ZSTD_seekable_decompress() error: %s\n",
ZSTD_getErrorName(result));
goto outfreezs;
}
if (result != expected_len) {
fprintf(stderr, "decoded %lu bytes, wanted %lu\n", result,
expected_len);
goto outfreezs;
}
ZSTD_seekable_free(zs);
goto out;
outfreezs:
ZSTD_seekable_free(zs);