Ensure StreamWriter is disposed before passed-in-Stream is disposed to prevent data loss (#241)