Inspired by https://github.com/adamhathcock/sharpcompress/pull/1169 Surely, this same logic can be reused in places.
Inspired by #1169
Surely, this same logic can be reused in places.