Big refactoring.

 - split out head & post. mixing them through the same block was getting messy.
 - less duplication. e.g. don't keep a separate bytesTotal and mix usage with
 self.file.size
 - consistent use of emitFail
 - proper handling of the case where server has not received anything yet
 - make lower-level functions less state-aware