[fix] Clear the buffer BEFORE write.

If you copy or override the _write method with your implementation that also queues the events back in the buffer even when it's opened. This would have caused the re-buffered events to be removed.