- raw_fd = topen(filename, O_RDONLY | O_BINARY);
- if (raw_fd < 0) {
- ERROR_WITH_ERRNO("Can't open \"%"TS"\" read-only", filename);
- return WIMLIB_ERR_OPEN;
+/* API function documented in wimlib.h */
+WIMLIBAPI int
+wimlib_set_output_compression_type(WIMStruct *wim, int ctype)
+{
+ int ret = set_out_ctype(ctype, &wim->out_compression_type);
+ if (ret)
+ return ret;
+
+ /* Reset the chunk size if it's no longer valid. */
+ if (!wim_chunk_size_valid(wim->out_chunk_size, ctype))
+ wim->out_chunk_size = wim_default_chunk_size(ctype);
+ return 0;
+}
+
+/* API function documented in wimlib.h */
+WIMLIBAPI int
+wimlib_set_output_pack_compression_type(WIMStruct *wim, int ctype)
+{
+ int ret = set_out_ctype(ctype, &wim->out_pack_compression_type);
+ if (ret)
+ return ret;
+
+ /* Reset the chunk size if it's no longer valid. */
+ if (!wim_chunk_size_valid(wim->out_pack_chunk_size, ctype))
+ wim->out_pack_chunk_size = wim_default_pack_chunk_size(ctype);
+ return 0;
+}
+
+static int
+set_out_chunk_size(u32 chunk_size, int ctype, u32 *out_chunk_size_p)
+{
+ if (!wim_chunk_size_valid(chunk_size, ctype)) {
+ ERROR("Invalid chunk size (%"PRIu32" bytes) "
+ "for compression type %"TS"!",
+ chunk_size,
+ wimlib_get_compression_type_string(ctype));
+ return WIMLIB_ERR_INVALID_CHUNK_SIZE;