Never write to original file, always write to .part, if need to write to original file then copy file ase <new>.part and then write to .part file.
Fix it so that 0 bytes are not written to the next file.