write_pack_header(): a helper function