summaryrefslogtreecommitdiffstats
path: root/tokio/src/fs/read.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/fs/read.rs')
-rw-r--r--tokio/src/fs/read.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/tokio/src/fs/read.rs b/tokio/src/fs/read.rs
new file mode 100644
index 00000000..88211228
--- /dev/null
+++ b/tokio/src/fs/read.rs
@@ -0,0 +1,27 @@
+use crate::fs::asyncify;
+
+use std::{io, path::Path};
+
+/// Creates a future which will open a file for reading and read the entire
+/// contents into a buffer and return said buffer.
+///
+/// This is the async equivalent of `std::fs::read`.
+///
+/// # Examples
+///
+/// ```no_run
+/// use tokio::fs;
+///
+/// # async fn dox() -> std::io::Result<()> {
+/// let contents = fs::read("foo.txt").await?;
+/// println!("foo.txt contains {} bytes", contents.len());
+/// # Ok(())
+/// # }
+/// ```
+pub async fn read<P>(path: P) -> io::Result<Vec<u8>>
+where
+ P: AsRef<Path>,
+{
+ let path = path.as_ref().to_owned();
+ asyncify(move || std::fs::read(path)).await
+}