X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=include%2Fwimlib%2Fresource.h;h=05ceed70b88b7b24e96f45296e324698cd14321c;hp=2fea2f579048759ce3d9b5c9784603b316694ce8;hb=43f92ce30b2398d1823e34e39ff248de521d015c;hpb=f1460c1d7df10acd410aea0496147c1abe9ef24c diff --git a/include/wimlib/resource.h b/include/wimlib/resource.h index 2fea2f57..05ceed70 100644 --- a/include/wimlib/resource.h +++ b/include/wimlib/resource.h @@ -192,6 +192,25 @@ wim_reshdr_to_hash(const struct wim_reshdr *reshdr, WIMStruct *wim, extern int skip_wim_resource(const struct wim_resource_descriptor *rdesc); +/* + * Callback function for reading chunks. Called whenever the next chunk of + * uncompressed data is available, passing 'ctx' as the last argument. 'size' is + * guaranteed to be nonzero. Must return 0 on success, or a positive wimlib + * error code on failure. + */ +struct consume_chunk_callback { + int (*func)(const void *chunk, size_t size, void *ctx); + void *ctx; +}; + +/* Pass a chunk of data to the specified consume_chunk callback */ +static inline int +consume_chunk(const struct consume_chunk_callback *cb, + const void *chunk, size_t size) +{ + return (*cb->func)(chunk, size, cb->ctx); +} + /* Callback functions for reading blobs */ struct read_blob_callbacks { @@ -205,7 +224,8 @@ struct read_blob_callbacks { /* Called when the next chunk of uncompressed data is available. 'size' * is guaranteed to be nonzero. Must return 0 on success, or a positive * wimlib error code on failure. */ - int (*consume_chunk)(const void *chunk, size_t size, void *ctx); + int (*continue_blob)(const struct blob_descriptor *blob, u64 offset, + const void *chunk, size_t size, void *ctx); /* Called when a blob has been successfully read (status=0), or when * begin_blob() was successfully called but an error occurred before the @@ -228,14 +248,15 @@ call_begin_blob(struct blob_descriptor *blob, return (*cbs->begin_blob)(blob, cbs->ctx); } -/* Call cbs->consume_chunk() if present. */ +/* Call cbs->continue_blob() if present. */ static inline int -call_consume_chunk(const void *chunk, size_t size, +call_continue_blob(const struct blob_descriptor *blob, u64 offset, + const void *chunk, size_t size, const struct read_blob_callbacks *cbs) { - if (!cbs->consume_chunk) + if (!cbs->continue_blob) return 0; - return (*cbs->consume_chunk)(chunk, size, cbs->ctx); + return (*cbs->continue_blob)(blob, offset, chunk, size, cbs->ctx); } /* Call cbs->end_blob() if present. */