diff --git a/src/fs/io/BufferedOutputStream.hxx b/src/fs/io/BufferedOutputStream.hxx
index 1df1c5dac..0541817f7 100644
--- a/src/fs/io/BufferedOutputStream.hxx
+++ b/src/fs/io/BufferedOutputStream.hxx
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2018 Max Kellermann <max.kellermann@gmail.com>
+ * Copyright 2014-2019 Max Kellermann <max.kellermann@gmail.com>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -88,4 +88,13 @@ private:
 #endif
 };
 
+template<typename F>
+void
+WithBufferedOutputStream(OutputStream &os, F &&f)
+{
+	BufferedOutputStream bos(os);
+	f(bos);
+	bos.Flush();
+}
+
 #endif