- u64 bytes_remaining = wim_resource_size(lte);
- u8 buf[min(WIM_CHUNK_SIZE, bytes_remaining)];
- u64 offset = 0;
- int ret = 0;
- u8 hash[SHA1_HASH_SIZE];
-
- SHA_CTX ctx;
- sha1_init(&ctx);
-
- while (bytes_remaining) {
- u64 to_read = min(bytes_remaining, WIM_CHUNK_SIZE);
- ret = read_wim_resource(lte, buf, to_read, offset, 0);
- if (ret != 0)
- break;
- sha1_update(&ctx, buf, to_read);
- if (ntfs_attr_pwrite(na, offset, to_read, buf) != to_read) {
- ERROR_WITH_ERRNO("Error extracting WIM resource");
- return WIMLIB_ERR_WRITE;
- }
- bytes_remaining -= to_read;
- offset += to_read;
- }
- sha1_final(hash, &ctx);
- if (!hashes_equal(hash, lte->hash)) {
- ERROR("Invalid checksum on a WIM resource "
- "(detected when extracting to NTFS stream)");
- ERROR("The following WIM resource is invalid:");
- print_lookup_table_entry(lte);
- return WIMLIB_ERR_INVALID_RESOURCE_HASH;
- }
- return 0;
+ return extract_wim_resource(lte, wim_resource_size(lte),
+ extract_wim_chunk_to_ntfs_attr, na);