From 3947b91b72731900ecfa74a81c22115325d7a869 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 6 Dec 2023 17:31:50 +0100 Subject: [PATCH] chore: add fs read (#5706) --- crates/primitives/src/fs.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/primitives/src/fs.rs b/crates/primitives/src/fs.rs index 8e4e50acd6..60f46e4da2 100644 --- a/crates/primitives/src/fs.rs +++ b/crates/primitives/src/fs.rs @@ -108,6 +108,14 @@ pub fn read_to_string(path: impl AsRef) -> Result { fs::read_to_string(path).map_err(|err| FsPathError::read(err, path)) } +/// Read the entire contents of a file into a bytes vector. +/// +/// Wrapper for `std::fs::read` +pub fn read(path: impl AsRef) -> Result> { + let path = path.as_ref(); + fs::read(path).map_err(|err| FsPathError::read(err, path)) +} + /// Wrapper for `std::fs::write` pub fn write(path: impl AsRef, contents: impl AsRef<[u8]>) -> Result<()> { let path = path.as_ref();