- DEBUG("Compressed %"PRIu64" => %"PRIu64" bytes; "
- "writing uncompressed instead",
- out_res_entry->original_size, out_res_entry->size);
- ret = seek_and_truncate(out_fd, res_start_offset);
- if (ret)
- goto out_free_chunk_tab;
- out_ctype = WIMLIB_COMPRESSION_TYPE_NONE;
- FREE(write_ctx.chunk_tab);
- write_ctx.out_ctype = WIMLIB_COMPRESSION_TYPE_NONE;
- write_ctx.chunk_tab = NULL;
- write_ctx.doing_sha = false;
- goto try_write_again;
- }
- if (resource_flags & (WIMLIB_READ_RESOURCE_FLAG_RAW)) {
- DEBUG("Copied raw compressed data "
- "(%"PRIu64" => %"PRIu64" bytes @ +%"PRIu64", flags=0x%02x)",
- out_res_entry->original_size, out_res_entry->size,
- out_res_entry->offset, out_res_entry->flags);
- } else if (out_ctype != WIMLIB_COMPRESSION_TYPE_NONE) {
- DEBUG("Wrote compressed resource "
- "(%"PRIu64" => %"PRIu64" bytes @ +%"PRIu64", flags=0x%02x)",
- out_res_entry->original_size, out_res_entry->size,
- out_res_entry->offset, out_res_entry->flags);
- } else {
- DEBUG("Wrote uncompressed resource "
- "(%"PRIu64" bytes @ +%"PRIu64", flags=0x%02x)",
- out_res_entry->original_size,
- out_res_entry->offset, out_res_entry->flags);
- }
- ret = 0;
-out_free_chunk_tab:
- FREE(write_ctx.chunk_tab);
-out:
- return ret;
-}
-
-/* Like write_wim_resource(), but the resource is specified by a buffer of
- * uncompressed data rather a lookup table entry; also writes the SHA1 hash of
- * the buffer to @hash_ret. */
-int
-write_wim_resource_from_buffer(const void *buf, size_t buf_size,
- int reshdr_flags, struct filedes *out_fd,
- int out_ctype,
- u32 out_chunk_size,
- struct resource_entry *out_res_entry,
- u8 *hash_ret, int write_resource_flags,
- struct wimlib_lzx_context **comp_ctx)
-{
- /* Set up a temporary lookup table entry to provide to
- * write_wim_resource(). */
- struct wim_lookup_table_entry lte;
- int ret;
-
- lte.resource_location = RESOURCE_IN_ATTACHED_BUFFER;
- lte.attached_buffer = (void*)buf;
- lte.resource_entry.original_size = buf_size;
- lte.resource_entry.flags = reshdr_flags;
- lte.compression_type = WIMLIB_COMPRESSION_TYPE_NONE;
-
- if (write_resource_flags & WIMLIB_WRITE_RESOURCE_FLAG_PIPABLE) {
- sha1_buffer(buf, buf_size, lte.hash);
- lte.unhashed = 0;
- } else {
- lte.unhashed = 1;
- }
-
- ret = write_wim_resource(<e, out_fd, out_ctype, out_chunk_size,
- out_res_entry, write_resource_flags, comp_ctx);
- if (ret)
- return ret;
- if (hash_ret)
- copy_hash(hash_ret, lte.hash);
- return 0;
-}