Refactor duplicate code for compression detection

Signed-off-by: Marc Delisle <marc@infomarc.info>