Stop the write loop when we have nothing to write, update append method to avoid copy in some case and update the test with this modification