Closes #20218: Added convenience methods read_text/write_text and read_bytes/
write_bytes to pathlib.Path objects.

Thanks to Christopher Welborn and Ram Rachum for original patches.
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index eff6ae3..5134eea 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -1083,6 +1083,39 @@
         return io.open(str(self), mode, buffering, encoding, errors, newline,
                        opener=self._opener)
 
+    def read_bytes(self):
+        """
+        Open the file in bytes mode, read it, and close the file.
+        """
+        with self.open(mode='rb') as f:
+            return f.read()
+
+    def read_text(self, encoding=None, errors=None):
+        """
+        Open the file in text mode, read it, and close the file.
+        """
+        with self.open(mode='r', encoding=encoding, errors=errors) as f:
+            return f.read()
+
+    def write_bytes(self, data):
+        """
+        Open the file in bytes mode, write to it, and close the file.
+        """
+        # type-check for the buffer interface before truncating the file
+        view = memoryview(data)
+        with self.open(mode='wb') as f:
+            return f.write(view)
+
+    def write_text(self, data, encoding=None, errors=None):
+        """
+        Open the file in text mode, write to it, and close the file.
+        """
+        if not isinstance(data, str):
+            raise TypeError('data must be str, not %s' %
+                            data.__class__.__name__)
+        with self.open(mode='w', encoding=encoding, errors=errors) as f:
+            return f.write(data)
+
     def touch(self, mode=0o666, exist_ok=True):
         """
         Create this file with the given access mode, if it doesn't exist.