'Finalize stream.'

def end(self):

    self._flush()
    if (self.len is None):
        contents = self.file.getvalue()
        self.len = len(contents)
        self.file = self.pdfFile.fh
        self._writeHeader()
        self.file.write(contents)
        self.file.write('\nendstream\nendobj\n')
    else:
        length = (self.file.tell() - self.pos)
        self.file.write('\nendstream\nendobj\n')
        self.pdfFile.writeObject(self.len, length)
