'Flush all buffers and free all resources.'

def close(self):

    self.endStream()
    if self.passed_in_file_object:
        self.fh.flush()
    else:
        if (self.original_file_like is not None):
            self.original_file_like.write(self.fh.getvalue())
        self.fh.close()
