[][src]Function async_std::fs::read

pub async fn read<P: AsRef<Path>>(path: P) -> Result<Vec<u8>>

Read the entire contents of a file into a bytes vector.

This is a convenience function for reading entire files. It pre-allocates a buffer based on the file size when available, so it is generally faster than manually opening a file and reading into a Vec.

This function is an async version of std::fs::read.

Errors

An error will be returned in the following situations (not an exhaustive list):

  • path does not exist.
  • The current process lacks permissions to read path.

Examples

use async_std::fs;

let contents = fs::read("a.txt").await?;