Add logging helper
Fix tests
Add null file test
Add image stream test
Only replace file contents when filesize is reduced