Buffer write & flush