- DEBUG("len = %lu", len);
- if (ctx->read_prefix_cb) {
- /* The length of the buffer passed to the ReadEncryptedFileRaw()
- * export callback is undocumented, so we assume it may be of
- * arbitrary size. */
- size_t bytes_to_buffer = min(ctx->bytes_remaining - ctx->buf_filled,
- len);
- while (bytes_to_buffer) {
- size_t bytes_to_copy_to_buf =
- min(bytes_to_buffer, in_chunk_size - ctx->buf_filled);
-
- memcpy(ctx->buf + ctx->buf_filled, data,
- bytes_to_copy_to_buf);
- ctx->buf_filled += bytes_to_copy_to_buf;
- data += bytes_to_copy_to_buf;
- bytes_to_buffer -= bytes_to_copy_to_buf;
-
- if (ctx->buf_filled == in_chunk_size ||
- ctx->buf_filled == ctx->bytes_remaining)
- {
- ret = (*ctx->read_prefix_cb)(ctx->buf,
- ctx->buf_filled,
- ctx->read_prefix_ctx_or_buf);
- if (ret) {
- ctx->wimlib_err_code = ret;
- /* Shouldn't matter what error code is returned
- * here, as long as it isn't ERROR_SUCCESS. */
- return ERROR_READ_FAULT;
- }
- ctx->bytes_remaining -= ctx->buf_filled;
- ctx->buf_filled = 0;
- }
- }
- } else {
- size_t len_to_copy = min(len, ctx->bytes_remaining);
- ctx->read_prefix_ctx_or_buf = mempcpy(ctx->read_prefix_ctx_or_buf,
- data,
- len_to_copy);
- ctx->bytes_remaining -= len_to_copy;
+ if (bytes_to_consume == 0)
+ return ERROR_SUCCESS;
+
+ ret = (*ctx->read_prefix_cb)(data, bytes_to_consume, ctx->read_prefix_ctx);
+ if (ret) {
+ ctx->wimlib_err_code = ret;
+ /* Shouldn't matter what error code is returned here, as long as
+ * it isn't ERROR_SUCCESS. */
+ return ERROR_READ_FAULT;