'If the schema is not present, presume we\'re appending.
@param writer: File-like object to write into.'

def __init__(self, writer, datum_writer, writers_schema=None, codec='null'):

    self._writer = writer
    self._encoder = io.BinaryEncoder(writer)
    self._datum_writer = datum_writer
    self._buffer_writer = StringIO()
    self._buffer_encoder = io.BinaryEncoder(self._buffer_writer)
    self._block_count = 0
    self._meta = {}
    self._header_written = False
    if (writers_schema is not None):
        if (codec not in VALID_CODECS):
            raise DataFileException(('Unknown    codec:    %r' % codec))
        self._sync_marker = DataFileWriter.generate_sync_marker()
        self.set_meta('avro.codec', codec)
        self.set_meta('avro.schema', str(writers_schema))
        self.datum_writer.writers_schema = writers_schema
    else:
        dfr = DataFileReader(writer, io.DatumReader())
        self._sync_marker = dfr.sync_marker
        self.set_meta('avro.codec', dfr.get_meta('avro.codec'))
        schema_from_file = dfr.get_meta('avro.schema')
        self.set_meta('avro.schema', schema_from_file)
        self.datum_writer.writers_schema = schema.parse(schema_from_file)
        writer.seek(0, 2)
        self._header_written = True
