Compressed temp files
This MR makes sure that we always write to a temp file before renaming the file to its final destination. This is something we should have been doing for ages, and is a good precaution to guard against bugs caused by half-written files.