flush the buffer after write