+/* Return true if the specified resource is compressed and the compressed data
+ * can be reused with the specified output parameters. */
+static bool
+can_raw_copy(const struct wim_lookup_table_entry *lte,
+ int write_resource_flags, int out_ctype, u32 out_chunk_size)
+{
+ return (out_ctype == wim_resource_compression_type(lte)
+ && out_chunk_size == wim_resource_chunk_size(lte)
+ && out_ctype != WIMLIB_COMPRESSION_TYPE_NONE);
+}
+
+
+/* Return true if the specified resource must be recompressed when the specified
+ * output parameters are used. */
+static bool
+must_compress_stream(const struct wim_lookup_table_entry *lte,
+ int write_resource_flags, int out_ctype, u32 out_chunk_size)
+{
+ return (out_ctype != WIMLIB_COMPRESSION_TYPE_NONE
+ && ((write_resource_flags & WIMLIB_WRITE_RESOURCE_FLAG_RECOMPRESS)
+ || !can_raw_copy(lte, write_resource_flags,
+ out_ctype, out_chunk_size)));
+}
+
+static unsigned
+compress_chunk(const void * uncompressed_data,
+ unsigned uncompressed_len,
+ void *compressed_data,
+ int out_ctype,
+ struct wimlib_lzx_context *comp_ctx)
+{
+ switch (out_ctype) {
+ case WIMLIB_COMPRESSION_TYPE_XPRESS:
+ return wimlib_xpress_compress(uncompressed_data,
+ uncompressed_len,
+ compressed_data);
+ case WIMLIB_COMPRESSION_TYPE_LZX:
+ return wimlib_lzx_compress2(uncompressed_data,
+ uncompressed_len,
+ compressed_data,
+ comp_ctx);
+ default:
+ wimlib_assert(0);
+ return 0;
+ }
+}
+