Refactor: libcrmcommon: Functionize writing compressed data to stream
Gets rid of some redundancies and hard-to-follow control flow.
Other minor changes:
- Return EIO instead of errno in case fprintf() fails. fprintf() doesn't set errno on error.
- Ensure filename is non-NULL.
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>