- /* Set up a chain of callbacks.
- *
- * The first level is the
- * streamifier_cb,
- * which takes in chunks of data and divides
- * them into the constituent streams.
- *
- * The second level are the SHA1 message digest
- * callbacks, which checksum each stream.
- *
- * rechunkifier_cb handles dividing the read
- * data into chunks of maximum size
- * @cb_chunk_size. If @cb_chunk_size is 0, then
- * this callback is not needed.
- *
- * Finally, the last level of callbacks are
- * @cbs, passed as arguments to this function.
- */
-
- struct rechunkifier_context *rechunkifier_ctx = NULL;
- consume_data_callback_t last_cb;
- void *last_cb_ctx;
-
- if (cb_chunk_size != 0) {
- rechunkifier_ctx = alloca(sizeof(*rechunkifier_ctx));
- *rechunkifier_ctx = (struct rechunkifier_context) {
- .buffer = MALLOC(cb_chunk_size),
- .buffer_filled = 0,
- .cb_chunk_size = cb_chunk_size,
- .ranges = ranges,
- .num_ranges = stream_count,
- .cur_range = 0,
- .range_bytes_remaining = ranges[0].size,
- .cb = cbs->consume_chunk,
- .cb_ctx = cbs->consume_chunk_ctx,
- };
-
- if (rechunkifier_ctx->buffer == NULL)
- return WIMLIB_ERR_NOMEM;
- last_cb = rechunkifier_cb;
- last_cb_ctx = rechunkifier_ctx;
- } else {
- rechunkifier_ctx = NULL;
- last_cb = cbs->consume_chunk;
- last_cb_ctx = cbs->consume_chunk_ctx;
- }
-
- struct hasher_context hasher_ctx = {
- .cbs = {
- .begin_stream = cbs->begin_stream,
- .begin_stream_ctx = cbs->begin_stream_ctx,
- .consume_chunk = last_cb,
- .consume_chunk_ctx = last_cb_ctx,
- .end_stream = cbs->end_stream,
- .end_stream_ctx = cbs->end_stream_ctx,
- },
- };
-