def flush(self): """ Flush to the binary file. :return: """ try: if self.__writeMode == Mode.Write: if self.isWindows: target = self.__path f = tempfile.TemporaryFile('w+b', -1, None, None, ".sf", "write") self.changePath(f.name) StateWriter(self, FileOutputStream.write(self.__makeInStream())) f._name = target self.changePath(target) else: StateWriter(self, FileOutputStream.write(self.__makeInStream())) return elif self.__writeMode == Mode.Append: if self.__dirty: self.changeMode(Mode.Write) self.flush() else: StateAppender( self, FileOutputStream.append(self.__makeInStream())) return elif self.__writeMode == Mode.ReadOnly: raise SkillException( "Cannot flush a read only file. Note: close will turn a file into read only." ) except SkillException as e: raise e except IOError as e: raise SkillException("failed to create or complete out stream", e) except Exception as e: raise SkillException("unexpected exception", e)
def writeSingleField(self, target, outstream: FileOutputStream): if target is None: outstream.f64(0) else: outstream.f64(target)