private function write_block()
    {
        if ($this->block_count > 0) {
            $this->encoder->write_long($this->block_count);
            $to_write = strval($this->buffer);
            $this->encoder->write_long(strlen($to_write));

            if (DataIO::is_valid_codec(
                $this->metadata[DataIO::METADATA_CODEC_ATTR])
            )
                $this->write($to_write);
            else
                throw new DataIOException(
                    sprintf('codec %s is not supported',
                        $this->metadata[DataIO::METADATA_CODEC_ATTR]));

            $this->write($this->sync_marker);
            $this->buffer->truncate();
            $this->block_count = 0;
        }
    }