pack-objects: move compression code in a separate function