/* *zstd_get_error_name()cannotbeusedbecauseerrortakesachar* *notaconstchar*
*/ switch (err) { case ZSTD_error_memory_allocation:
error("ZSTD decompressor ran out of memory"); break; case ZSTD_error_prefix_unknown:
error("Input is not in the ZSTD format (wrong magic bytes)"); break; case ZSTD_error_dstSize_tooSmall: case ZSTD_error_corruption_detected: case ZSTD_error_checksum_wrong:
error("ZSTD-compressed data is corrupt"); break; default:
error("ZSTD-compressed data is probably corrupt"); break;
} return -1;
}
/* *Handlethecasewherewehavetheentireinputandoutputinonesegment. *Wecanallocatelessmemory(nocircularbufferfortheslidingwindow), *andavoidsomememcpy()calls.
*/ staticint INIT decompress_single(const u8 *in_buf, long in_len, u8 *out_buf, long out_len, long *in_pos, void (*error)(char *x))
{ const size_t wksp_size = zstd_dctx_workspace_bound(); void *wksp = large_malloc(wksp_size);
zstd_dctx *dctx = zstd_init_dctx(wksp, wksp_size); int err;
size_t ret;
if (dctx == NULL) {
error("Out of memory while allocating zstd_dctx");
err = -1; goto out;
} /* *Findouthowlargetheframeactuallyis,theremaybejunkat *theendoftheframethatzstd_decompress_dctx()can'thandle.
*/
ret = zstd_find_frame_compressed_size(in_buf, in_len);
err = handle_zstd_error(ret, error); if (err) goto out;
in_len = (long)ret;
ret = zstd_decompress_dctx(dctx, out_buf, out_len, in_buf, in_len);
err = handle_zstd_error(ret, error); if (err) goto out;
/* *Ifin_bufisnotprovided,wemustbeusingfill(),soallocate *alargeenoughbuffer.Ifitisprovided,itmustbeatleast *ZSTD_IOBUF_SIZElarge.
*/ if (in_buf == NULL) {
in_allocated = large_malloc(ZSTD_IOBUF_SIZE); if (in_allocated == NULL) {
error("Out of memory while allocating input buffer");
err = -1; goto out;
}
in_buf = in_allocated;
in_len = 0;
} /* Read the first chunk, since we need to decode the frame header. */ if (fill != NULL)
in_len = fill(in_buf, ZSTD_IOBUF_SIZE); if (in_len < 0) {
error("ZSTD-compressed data is truncated");
err = -1; goto out;
} /* Set the first non-empty input buffer. */
in.src = in_buf;
in.pos = 0;
in.size = in_len; /* Allocate the output buffer if we are using flush(). */ if (flush != NULL) {
out_allocated = large_malloc(ZSTD_IOBUF_SIZE); if (out_allocated == NULL) {
error("Out of memory while allocating output buffer");
err = -1; goto out;
}
out_buf = out_allocated;
out_len = ZSTD_IOBUF_SIZE;
} /* Set the output buffer. */
out.dst = out_buf;
out.pos = 0;
out.size = out_len;
/* *Weneedtoknowthewindowsizetoallocatethezstd_dstream. *Sincewearestreaming,weneedtoallocateabufferforthesliding *window.Thewindowsizevariesfrom1KBtoZSTD_WINDOWSIZE_MAX *(8MB),soitisimportanttousetheactualvaluesoasnotto *wastememorywhenitissmaller.
*/
ret = zstd_get_frame_header(&header, in.src, in.size);
err = handle_zstd_error(ret, error); if (err) goto out; if (ret != 0) {
error("ZSTD-compressed data has an incomplete frame header");
err = -1; goto out;
} if (header.windowSize > ZSTD_WINDOWSIZE_MAX) {
error("ZSTD-compressed data has too large a window size");
err = -1; goto out;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.