write buf at end