25void R__zipZSTD(
int cxlevel,
int *srcsize,
const char *src,
int *tgtsize,
char *tgt,
int *irep)
27 using Ctx_ptr = std::unique_ptr<ZSTD_CCtx,
decltype(&ZSTD_freeCCtx)>;
28 Ctx_ptr fCtx{ZSTD_createCCtx(), &ZSTD_freeCCtx};
32 size_t retval = ZSTD_compressCCtx(fCtx.get(),
34 src,
static_cast<size_t>(*srcsize),
39 std::cerr <<
"Error in zip ZSTD. Type = " << ZSTD_getErrorName(retval) <<
40 " . Code = " << retval << std::endl;
48 size_t deflate_size = retval;
49 size_t inflate_size =
static_cast<size_t>(*srcsize);
53 tgt[3] = deflate_size & 0xff;
54 tgt[4] = (deflate_size >> 8) & 0xff;
55 tgt[5] = (deflate_size >> 16) & 0xff;
56 tgt[6] = inflate_size & 0xff;
57 tgt[7] = (inflate_size >> 8) & 0xff;
58 tgt[8] = (inflate_size >> 16) & 0xff;
61void R__unzipZSTD(
int *srcsize,
const unsigned char *src,
int *tgtsize,
unsigned char *tgt,
int *irep)
63 using Ctx_ptr = std::unique_ptr<ZSTD_DCtx,
decltype(&ZSTD_freeDCtx)>;
64 Ctx_ptr fCtx{ZSTD_createDCtx(), &ZSTD_freeDCtx};
68 std::cerr <<
"R__unzipZSTD: algorithm run against buffer with incorrect header (got " <<
69 src[0] << src[1] <<
"; expected ZS)." << std::endl;
73 int ZSTD_version = ZSTD_versionNumber() / (100 * 100);
75 std::cerr <<
"R__unzipZSTD: This version of ZSTD is incompatible with the on-disk version "
76 "got "<< src[2] <<
"; expected "<< ZSTD_version <<
")" << std::endl;
80 size_t retval = ZSTD_decompressDCtx(fCtx.get(),
81 (
char *)tgt,
static_cast<size_t>(*tgtsize),
89 std::cerr <<
"Error in unzip ZSTD. Type = " << ZSTD_getErrorName(retval) <<
90 " . Code = " << retval << std::endl;
void R__zipZSTD(int cxlevel, int *srcsize, const char *src, int *tgtsize, char *tgt, int *irep)