panzi / rust-u4pak

unpack, pack, list, check and mount Unreal Engine 4 .pak archives
Mozilla Public License 2.0
140 stars 11 forks source link

Add compression threshold #26

Open Xenira opened 2 years ago

Xenira commented 2 years ago

UnrealPak does not compress files that can't get much smaller by compressing them. This should also be supported by u4pak, as the compression block overhead inflates the file unnecessarily and extracting compressed resources takes more computation. Also might reduce the size difference noted in #25.

TODO:

panzi commented 2 years ago

Didn't I do this already? (For small files.) Or am I thinking of one of my other game archive programs/scripts?

Xenira commented 2 years ago

There is a switch for small files here: https://github.com/panzi/rust-u4pak/blob/7b25c3e1904a7a57ea79733ab77ee6d5f39dc19c/src/pack.rs#L587 Did not see a threshold

panzi commented 2 years ago

Ok, I've added an option for the threshold of files under which they shan't be compressed. See --compression-min-size

panzi commented 2 years ago

Also it now checks if the file didn't shrink after compression and writes the uncompressed file instead in that case. This feature needs testing.

Xenira commented 2 years ago

Also it now checks if the file didn't shrink after compression and writes the uncompressed file instead in that case. This feature needs testing.

This is actually what I wanted to do in this issue :)

panzi commented 2 years ago

Yeah, I felt like implementing that. :smile: Do you have any tests with files where you know they grow in size when trying to compress them?

Xenira commented 2 years ago

The current files should have a jpg, that is not compressed (need to add a png, to test compression with larger files when I think about it).